[Tfug] Need help with a C++ algorithm
Brian Murphy
murphy+tfug at email.arizona.edu
Thu Mar 15 14:34:13 MST 2007
Quoting Stephen Hooper <stephen.hooper at gmail.com>:
> On 3/15/07, Brian Murphy
>> Replace
>> start = malloc(strtol(argv[1],NULL,16) * sizeof(char));
>>
>> with
>>
>> char string[100];
>> start = string;
>>
>> QED. :-)
>
>
> In which case (and which I didn't really think he was asking about),
> you should really know the value anyway (in your case:
> sizeof(string)/sizeof(char)).
You should because you train yourself that way when you learn C. But if
we take the basic question of finding the size of the memory block and
only the pointer is known, then you can't. I accept your
sizeof(string) function, but string isn't the notable pointer here --
start is. And sizeof(start) will return the pointer size, not the
array size.
I'll agree with you that if you can guarentee it was a dynamic
allocation and you guarentee the allocator implementation that you can
dig out the chunk size. :) However that is IMO beyond only knowing a
pointer.
> "quod erat demonstrandum": Getting a little cocky now that you are
> superhero? ;)
I figured QED was nicer than pwn3d.
B
The opinions or statements expressed herein are my own and should not be
taken as a position, opinion, or endorsement of the University of
Arizona.
More information about the tfug
mailing list