[R-gregmisc-users] SF.net SVN: r-gregmisc:[1855] trunk/SASxport/src/ibm2ieee.c
Brought to you by:
warnes
From: <wa...@us...> - 2014-07-21 13:50:07
|
Revision: 1855 http://sourceforge.net/p/r-gregmisc/code/1855 Author: warnes Date: 2014-07-21 13:49:59 +0000 (Mon, 21 Jul 2014) Log Message: ----------- Avoid infinte loop in case of IBM exponent overflow. If this occurs, and can't be fixed in a single pass, generate a warning message and return NA. Modified Paths: -------------- trunk/SASxport/src/ibm2ieee.c Modified: trunk/SASxport/src/ibm2ieee.c =================================================================== --- trunk/SASxport/src/ibm2ieee.c 2014-07-21 13:47:50 UTC (rev 1854) +++ trunk/SASxport/src/ibm2ieee.c 2014-07-21 13:49:59 UTC (rev 1855) @@ -50,6 +50,10 @@ * No hidden bits in mantissa (56 bits). */ register int i; + int loop = 0; + + static char numeric_NA[8] = {0x2e,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + for( i=count-1; i >= 0; i-- ) { register unsigned int left, right, signbit; register int exp; @@ -122,6 +126,16 @@ * This case was not expected, but does happen, * at least on the Gould. */ + if(loop) + { + warning("IBM exponent overflow, generating NA\n"); + memcpy(out, numeric_NA, 8); + out+= 8; + continue; + } + else + loop = 1; + exp -= 4; left = ( (unsigned int) left<<4) | (right>>(32-4)); right <<= 4; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |