@@ -2067,18 +2067,15 @@ showfiles(void)
20672067static void
20682068getscanfield (FILE * fp , bool skip , unsigned int width , int scannum , char * scanptr , char * * strptr )
20692069{
2070- char * str ; /* current string */
2071- unsigned long len ; /* current length of string */
2072- unsigned long totlen ; /* total length of string */
2073- char buf [READSIZE ]; /* temporary buffer */
2070+ char * str = NULL ; /* current string */
2071+ unsigned long len ; /* current length of string */
2072+ unsigned long totlen = 0 ; /* total length of string */
2073+ char buf [READSIZE ]; /* temporary buffer */
20742074 int c ;
20752075 char * b ;
20762076 bool comp ; /* Use complement of scanset */
20772077 unsigned int chnum ;
20782078
2079- totlen = 0 ;
2080- str = NULL ;
2081-
20822079 comp = (scannum < 0 );
20832080 if (comp ) {
20842081 scannum = - scannum ;
@@ -2111,12 +2108,18 @@ getscanfield(FILE *fp, bool skip, unsigned int width, int scannum, char *scanptr
21112108 }
21122109 if (!skip ) {
21132110 if (totlen ) {
2114- str = (char * )realloc (str , totlen + len + 1 );
2111+ if (str == NULL ) {
2112+ /* paranoia */
2113+ math_error ("getscanfield: str was NULL while totlen != 0" );
2114+ not_reached ();
2115+ } else {
2116+ str = (char * )realloc (str , totlen + len + 1 );
2117+ }
21152118 } else {
21162119 str = (char * )calloc (len + 1 , 1 );
21172120 }
21182121 if (str == NULL ) {
2119- math_error ("Out of memory for scanning" );
2122+ math_error ("getscanfield: Out of memory for scanning" );
21202123 not_reached ();
21212124 }
21222125 if (len ) {
@@ -2233,8 +2236,8 @@ fscanfile(FILE *fp, char *fmt, int count, VALUE **vals)
22332236 int scannum ; /* Number of characters in scanlist */
22342237 char * scanptr ; /* Start of scanlist */
22352238 char * str = NULL ;
2236- bool comp ; /* True scanset is complementary */
2237- bool skip ; /* True if string to be skipped rather than read */
2239+ bool comp = false; /* True scanset is complementary */
2240+ bool skip = false; /* True if string to be skipped rather than read */
22382241 int width ;
22392242 VALUE * var ; /* lvalue to be assigned to */
22402243 unsigned short subtype ; /* for var->v_subtype */
@@ -2333,7 +2336,8 @@ fscanfile(FILE *fp, char *fmt, int count, VALUE **vals)
23332336 assnum ++ ;
23342337 var = * vals ++ ;
23352338 if (var -> v_type != V_ADDR ) {
2336- math_error ("This should not happen!!" );
2339+ math_error ("fscanfile: i case and var->v_type != V_ADDR" );
2340+ not_reached ();
23372341 }
23382342 var = var -> v_addr ;
23392343 subtype = var -> v_subtype ;
@@ -2347,7 +2351,8 @@ fscanfile(FILE *fp, char *fmt, int count, VALUE **vals)
23472351 var = * vals ++ ;
23482352 count -- ;
23492353 if (var -> v_type != V_ADDR ) {
2350- math_error ("This should not happen!!" );
2354+ math_error ("fscanfile: n case and var->v_type != V_ADDR" );
2355+ not_reached ();
23512356 }
23522357 var = var -> v_addr ;
23532358 subtype = var -> v_subtype ;
@@ -2367,12 +2372,18 @@ fscanfile(FILE *fp, char *fmt, int count, VALUE **vals)
23672372 var = * vals ++ ;
23682373 count -- ;
23692374 if (var -> v_type != V_ADDR ) {
2370- math_error ("Assigning to non-variable" );
2375+ math_error ("fscanfile: assigning to non-variable" );
2376+ not_reached ();
23712377 }
23722378 var = var -> v_addr ;
23732379 subtype = var -> v_subtype ;
23742380 freevalue (var );
23752381 var -> v_type = V_STR ;
2382+ if (str == NULL ) {
2383+ /* paranoia */
2384+ math_error ("fscanfile: getscanfield not called and/or str is NULL" );
2385+ not_reached ();
2386+ }
23762387 var -> v_str = makestring (str );
23772388 }
23782389 }
0 commit comments