-
-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
r3.in.v5d: Prevent integer overflow by changing literal constant type on Cray #4363
Conversation
23c793f
to
88ac3b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Min size of long int is 32 so that still can overflow. I get -Wshift-count-overflow
. I think LL
is needed.
88ac3b4
to
eafb70f
Compare
@wenzeslaus : Thank you for pointing that issue! I spent good amount of time thinking about it earlier. If for example Ex: So, I assumed it would be safe as Using (I was also a bit worried if CRAY supports I am also curious about how you got to this |
Looking into this more, I don't find clear info on when |
One of the online C/C++ compilers :-) I checked just the expression, not the whole file or source code. |
The CRAY additions were made in mid-90s, some time ago. Not likely that code is relevant anymore. So long or long long probably doesn't matter much. (However the function parameters are longs and thus the variables involved in the bit shift, so too I believe should be the literals in this fix.) |
Sorry @ymdatta, can you please change this to be consistent with the rest of the code by using L not LL as I previosly suggested. We will let |
We may also consider remove the "CRAY" code, unless someone is actually using GRASS GIS with present CRAY (and would be able to assist...). |
The code was probably originated from https://sourceforge.net/projects/vis5d/ (see mirror at https://github.com/drafnel/Vis5d/blob/master/src/binio.c) |
Seems I have added it to GRASS GIS 25 years ago (on May 2, 2000): OSGeo/grass-legacy@09c5679#diff-45d5ff840b803deffa0d4cbc279dc064524276c0350c4630036d7a2e13a75737 but don't see any related discussion in the grass-dev archive... |
When the code is being compiled for CRAY HPC machines, a macro and a function to convert IEEE single precision floating point number to CRAY number are defined. To adjust the base, '16258' constant is being used, which according to C rules (C99, section 6.4.4.1, subsection semantics) fits into an integer. Right shifting that integer, which is of 32 bits, by 48 results in integer overflow. Avoid this by defining the literal constant with the long data type. Signed-off-by: Mohan Yelugoti <[email protected]>
eafb70f
to
90dcdb8
Compare
Modified the literal back to long. Even the magic number in the code Let's say, if exponent in the IEEE format is But, it took me some time going through CRAY manuals to get here. If we are not using this anywhere, I would also suggest removing it to keep the code simple. |
@ymdatta Sorry, realized only now this was still pending. Can you please remove the Cray code in a new PR? |
@wenzeslaus : No problem. I'll open a PR removing Cray specific code. |
When the code is being compiled for CRAY HPC machines, a macro and a function to convert IEEE single precision floating point number to CRAY number are defined.
To adjust the base, '16258' constant is being used, which according to C rules (C99, section 6.4.4.1, subsection semantics) fits into an integer. Right shifting that integer, which is of 32 bits, by 48 results in integer overflow. Avoid this by defining the literal constant with the long data type.