Re: Cannot compile with _FILE_OFFSET_BITS = 64



Ravishankar S wrote:
"Scott.zhou" <rwxrxrx@xxxxxxxxx> wrote in message
news:fla6k1$j8h$1@xxxxxxxxxxxxxxxx
....
25 if (lseek(fd, 4*1024*1024*1024, SEEK_SET) == -1) { // integer
overflow
No automatic conversion to 64 bit type is done by compiler. So make it
explicit by making one of the constants as 64 bit type. This makes entire
expression 64 bit.

=> 4*1024*1024*1024LL // 64 Bit constant made by LL suffix.

That's not sufficient. The above is equivalent to ((((4*1024)*1024)*1024LL). The very first multiplication is safe; but the second one might overflow, depending upon the value of INT_MAX. You could solve this by moving the LL to the second 1024, but I think that's an overly subtle solution; a maintenance programmer might not realize why the exact position of the 'LL' is critical. I'd apply the LL suffix to all 4.
.



Relevant Pages

  • Re: Cannot compile with _FILE_OFFSET_BITS = 64
    ... 12 int main{ ... No automatic conversion to 64 bit type is done by compiler. ... explicit by making one of the constants as 64 bit type. ...
    (comp.lang.c)
  • Re: Adding Older Versions of GCC To The Tool Chain ... safely?!?!
    ... doing optimizing? ... The original "vulnerability" report, not just the Heise article, uses ... There is by definition no such thing as 'an unsigned overflow', ... and a C compiler is still free to do whatever it chooses. ...
    (comp.os.linux.development.apps)
  • Re: extended operators
    ... between the sequence point X and the last sequence point. ... Perhaps it should be a macro, defined in a new header, that expands to some implementation-defined expression (possibly involving compiler magic). ... So you'd mandate specific restrictions on generated code in the presence of calls to _carry, even if the compiler is able to prove that it can perform an optimization without changing the effect? ... The ``result'' member is set to the sum of x and y; unlike an ordinary "+" operator, the result is well defined even on overflow. ...
    (comp.std.c)
  • Re: operators similar to functions?
    ... undefined behaviour; however the compiler cannot know that. ... probably has a pretty good idea of the consequences of overflow ... The HAL StinkWad represents an opposite pole in system design. ...
    (comp.lang.c)
  • Re: where exactly c++,c fail and Ada gets thru
    ... The simplistic answer is for each ranged type R, ... basically done by partial specializing on whether overflow is possible. ... tried to shove it into a variable without enough digits, ... for speed if their compiler supported inline assembly). ...
    (comp.lang.ada)