[interfacekit] Re: OBOS Support kit doesn't compile: solution

Although I can't check out the file, test it or check it back in, I 
think I know what should be done to fix it.  Lines which are failing 
look like:

fPropInfo[pi].name=strdup(static_cast<char *>(buffer)+
flatData.Position());

This code is trying to do the following:
- buffer is the data which has the flattened raw data (const void *)
- it is currently decoding the data at the offset "flatData.Position()"
- at this location is a NULL terminated string according to how 
BPropertyInfo is flattened
- it copies this string to a new dynamically allocated location using 
strdup()
- it needs to cast the buffer to a char * for strdup() to work

The "buffer" local is "const void *" so the static_cast is trying to go 
from a "const void *" to a "char *".  However, strdup() takes a "const 
char *" so the following should also work:

fPropInfo[pi].name=strdup(static_cast<const char *>(buffer)+
flatData.Position());

This should compile without errors because in this case the static cast 
is not attempting to cast away "const-ness".  And strdup() shouldn't 
have any problem with this either.  There are five instances of this 
code which needs to be changed.

I can't explain why myself nor Ingo cannot reproduce this.  There must 
be some difference between the compilers being used out there which is 
a bit scary.  However, I agree that this code is a defect.

As I can't do more testing or checking in of this change, if someone 
wants to try changing the static_cast to "const char *" for these five 
cases and check it in for me, that would be great.  Sorry again for the 
build problems.

>>Unfortunately, as I mentioned by Intel BeOS machine is dead and will 
>>probably not be running again until Saturday at the earliest.  I will 
>>look at it as soon as I have a machine running again.  Sorry about 
the 
>>problem and the delay.
>
>Oops!  My bad.  Hope your machine is well again soon. ;)
>
>e
>
>>>Unless I'm mistaken, BPropertyInfo is assigned to Jeremy Rand.  
>>Jeremy, 
>>>can you take a look at this?
>>>
>>>Thanks,
>>>
>>>e
>>>
>>>Jack Burton wrote:
>>>> Now that I am a little confident with jam, 
>>>> I finally found what's the problem with our support kit:
>>>> PropertyInfo fails to compile:
>>>> Here's the output of gcc:
>>>> 
>>>> "/boot/home/progetti/openbeos/current/src/kits/app/
PropertyInfo.cpp: 
>
>>In 
>>>> method `status_t BPropertyInfo::Unflatten(long unsigned int, const 
>>void *, 
>>>> long int)':
>>>> /boot/home/progetti/openbeos/current/src/kits/app/
>>PropertyInfo.cpp:302: 
>>>> static_cast from `const void *' to `char *' casts away constness
>>>> /boot/home/progetti/openbeos/current/src/kits/app/
>>PropertyInfo.cpp:305: 
>>>> static_cast from `const void *' to `char *' casts away constness
>>>> /boot/home/progetti/openbeos/current/src/kits/app/
>>PropertyInfo.cpp:348: 
>>>> static_cast from `const void *' to `char *' casts away constness
>>>> /boot/home/progetti/openbeos/current/src/kits/app/
>>PropertyInfo.cpp:378: 
>>>> static_cast from `const void *' to `char *' casts away constness
>>>> /boot/home/progetti/openbeos/current/src/kits/app/
>>PropertyInfo.cpp:381: 
>>>> static_cast from `const void *' to `char *' casts away constness
>>>> 
>>>> gcc  -c "../../src/kits/app/PropertyInfo.cpp"  -O1   -I../../src/
>>kits 
>>>> -I../../src/kits/app -I../../src/kits/interface -I../../src/kits/
>>support 
>>>> -I../../src/kits/storage -I../../src/kits/storage/mime 
>>>> -I../../src/kits/storage/sniffer -I../../headers/private/app 
>>>> -I../../headers/os/app -I../../headers/private/interface 
>>>> -I../../headers/os/interface -I../../headers/private/support 
>>>> -I../../headers/os/support -I../../headers/private/storage 
>>>> -I../../headers/os/storage -I../../headers/os/add-ons/file_system 
>>>> -I../../headers/private/shared  -o 
>>>> "../../objects/x86.R1/kits/PropertyInfo.o"  ;
>>>> 
>>>> ...failed C++ ../../objects/x86.R1/kits/PropertyInfo.o ...
>>>> ...skipped libopenbeos.so for lack of <src!kits>PropertyInfo.o...
>>>> ...skipped <boot!home!config!lib>libopenbeos.so for lack of 
>>>> libopenbeos.so..."
>>>> 
>>>> etc. etc. 
>>>> 
>>>> Marc, should I fix it, or will you do it ? :)
>>>> 
>>>> 
>>>
>>>
>>>
>>--
>>Jeremy Rand
>>jrand@xxxxxxxx
>
>Necessity is the plea for every infringement of human freedom. It is 
the 
>argument of tyrants; it is the creed of slaves.
>       -William Pitt, British prime-minister (1759-1806)

--
Jeremy Rand
jrand@xxxxxxxx

Other related posts: