5

Operation on 'xxx' may be undefined

view full story
linux-howto

http://forums.opensuse.org – This is a classic situation (example taken from Michel Xhaards jpegenc library): Code:   for (i = rows; i > 0; i--)     {       for (j = cols; j > 0; j--)         *Y1_Ptr++ = *input_ptr++ - 128;       for (j = 8 - cols; j > 0; j--)         *Y1_Ptr++ = *(Y1_Ptr - 1);       input_ptr += incr;     } Look at line 6 of this code snippet. It throws a warning like this: Code: encoder.c:392: warning: operation on 'Y1_Ptr' may be undefined The warning is justified because things can go wrong. It is entirely up to the compiler what the value of Y1_Ptr would be in the right part of the line. It is undefined according to the standard. Only the original coder knows what the code should do in his opinion. Code like this can not be packaged. I have to patch it. Would you think that this fix meets the original intentions: Code: *Y1_Ptr = *(Y1_Ptr - 1); Y1_Ptr++; Any comments would be helpful. (Distributions)