Changeset 39324 for trunk/Ohana/src/libfits/header/F_scan.c
- Timestamp:
- Jan 27, 2016, 11:18:36 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libfits/header/F_scan.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/header/F_scan.c
r34405 r39324 44 44 if (p[8] != '=') return (FALSE); 45 45 46 s = gfits_keyword_start (p); /* points at first char (not ') */ 47 q = gfits_keyword_end (p); /* points at following space or ' */ 48 49 // these are invalid conditions: 50 if (s - p > 80) return FALSE; 51 if (q - p > 80) return FALSE; 52 46 53 /* extract data into char array (exclude containing ' chars) */ 54 Nchar = MIN (80, MAX (0, (q - s))); 55 bzero (tmp, 81); 56 memcpy (tmp, s, Nchar); 57 58 // for string types, copy the data to the target pointer 47 59 if (!strcmp (mode, "%s")) { 48 s = gfits_keyword_start (p); /* points at first char (not ') */49 q = gfits_keyword_end (p); /* points at following space or ' */50 51 Nchar = MAX (0, (q - s));52 bzero (tmp, 81);53 memcpy (tmp, s, Nchar);54 60 stripwhite (tmp); 55 61 strcpy (va_arg (argp, char *), tmp); … … 59 65 /* remaining options are numerical data */ 60 66 /* need to interpret 1.0d5 as 1.0e5 */ 61 s = gfits_keyword_start (p); /* points at first char (not ') */62 q = gfits_keyword_end (p); /* points at following space or ' */63 67 64 68 if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) { 65 fvalue = strtod (s, &q); 66 if ((*q == 'd') || (*q == 'D')) 67 fvalue *= pow (10.0, atof (q + 1)); 69 fvalue = strtod (tmp, &q); 70 if ((*q == 'd') || (*q == 'D')) fvalue *= pow (10.0, atof (q + 1)); 68 71 69 72 if (!strcmp (mode, "%f")) { *va_arg (argp, float *) = fvalue; return (TRUE); } … … 71 74 } 72 75 73 value = strtoll ( s, &q, 0);76 value = strtoll (tmp, &q, 0); 74 77 if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1)); 75 78 … … 96 99 int gfits_vscan_alt (Header *header, char *field, char *mode, int N, va_list argp) { 97 100 98 char *p, *q, *s, tmp[ 81];101 char *p, *q, *s, tmp[128]; 99 102 int Nchar, status; 100 103 … … 117 120 /* comment from data line */ 118 121 if (!strcmp (mode, "%C")) { 119 q = gfits_keyword_end (p) + 3; 122 q = gfits_keyword_end (p); 123 if (!q) return (FALSE); 124 q += 3; 120 125 q = MIN (p + 80, q); 121 126 bzero (tmp, 81); 122 Nchar = M IN (80, p + 80 - q);127 Nchar = MAX (0, MIN (80, p + 80 - q)); 123 128 memcpy (tmp, q, Nchar); 124 129 stripwhite (tmp); … … 147 152 int gfits_vscan_hierarch (Header *header, char *field, char *mode, int N, va_list argp) { 148 153 149 char *p, *q, *s, tmp[ 81];154 char *p, *q, *s, tmp[128]; 150 155 int Nchar, Nfield; 151 156 long long value; … … 172 177 q = MIN (p + HIERARCH_LENGTH, q); 173 178 bzero (tmp, 81); 174 Nchar = M IN (HIERARCH_LENGTH, p + HIERARCH_LENGTH - q);179 Nchar = MAX (0, MIN (HIERARCH_LENGTH, p + HIERARCH_LENGTH - q)); 175 180 memcpy (tmp, q, Nchar); 176 181 stripwhite (tmp); … … 179 184 } 180 185 181 /* extract data into char array (exclude containing ' chars) */ 182 if (!strcmp (mode, "%s")) { 183 s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */ 184 q = gfits_hierarch_keyword_end (p, field); /* points at following space or ' */ 185 186 Nchar = MIN (HIERARCH_LENGTH, MAX (0, (q - s))); 187 bzero (tmp, 81); 188 memcpy (tmp, s, Nchar); 189 stripwhite (tmp); 190 strcpy (va_arg (argp, char *), tmp); 191 return (TRUE); 192 } 193 186 s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */ 187 q = gfits_hierarch_keyword_end (p, field); /* points at following space or ' */ 188 189 // these are invalid conditions: 190 if (s - p > 80) return FALSE; 191 if (q - p > 80) return FALSE; 192 194 193 /* boolean data, requires int target */ 195 194 if (!strcmp (mode, "%t")) { 196 s = gfits_hierarch_keyword_start (p, field);197 195 if (*s == 'T') { 198 196 *va_arg (argp, int *) = TRUE; … … 205 203 } 206 204 205 /* extract data into char array (exclude containing ' chars) */ 206 Nchar = MIN (HIERARCH_LENGTH, MAX (0, (q - s))); 207 bzero (tmp, 81); 208 memcpy (tmp, s, Nchar); 209 210 // for string types, copy the data to the target pointer 211 if (!strcmp (mode, "%s")) { 212 stripwhite (tmp); 213 strcpy (va_arg (argp, char *), tmp); 214 return (TRUE); 215 } 216 207 217 /* remaining options are numerical data */ 208 218 /* need to interpret 1.0d5 as 1.0e5 */ 209 s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */210 q = gfits_hierarch_keyword_end (p, field); /* points at following space or ' */211 219 212 220 if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) { 213 fvalue = strtod (s, &q); 214 if ((*q == 'd') || (*q == 'D')) 215 fvalue *= pow (10.0, atof (q + 1)); 221 fvalue = strtod (tmp, &q); 222 if ((*q == 'd') || (*q == 'D')) fvalue *= pow (10.0, atof (q + 1)); 216 223 217 224 if (!strcmp (mode, "%f")) { *va_arg (argp, float *) = fvalue; return (TRUE); } … … 219 226 } 220 227 221 value = strtoll ( s, &q, 0);228 value = strtoll (tmp, &q, 0); 222 229 if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1)); 223 230
Note:
See TracChangeset
for help on using the changeset viewer.
