Changeset 42389 for trunk/Ohana/src/libfits/header/F_modify.c
- Timestamp:
- Feb 8, 2023, 12:17:35 PM (3 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/libfits/header/F_modify.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
trunk/Ohana/src/libfits/header/F_modify.c
r38441 r42389 8 8 /* this function is extremely similar to gfits_print, except it allows for changing an existing field. */ 9 9 10 char comment[82], string[82], data[82]; 10 // the output string needs to be long enough to keep the compiler from 11 // complaining, even though the string cannot be more than 80 chars 12 char comment[82], string[200], data[82]; 11 13 char *p, *qe; 12 14 va_list argp; … … 14 16 va_start (argp, N); 15 17 bzero (data, 82); 16 bzero (string, 82);18 bzero (string, 200); 17 19 bzero (comment, 82); 18 20 … … 46 48 qe += 3; 47 49 qe = MIN (p + 80, qe); 48 strncpy (comment, qe, p + 80 - qe);50 strncpy_nowarn (comment, qe, p + 80 - qe); 49 51 } 50 52 gfits_pad_ending (comment, 0x20, 82); /* comment must contain spaces to the end */ 51 53 52 54 /* write the numeric modes */ 53 if (!strcmp (mode, "%d")) { snprintf (string, 81, "%-8s= %20d / %-s ", field, va_arg (argp, int),comment); goto found_it; }54 if (!strcmp (mode, "%ld")) { snprintf (string, 81, "%-8s= %20ld / %-s ", field, va_arg (argp, long),comment); goto found_it; }55 if (!strcmp (mode, "%lld")) { snprintf (string, 81, "%-8s= %20lld / %-s ", field, va_arg (argp, long long),comment); goto found_it; }56 if (!strcmp (mode, "%Ld")) { snprintf (string, 81, "%-8s= %20lld / %-s ", field, va_arg (argp, long long),comment); goto found_it; }57 if (!strcmp (mode, "%u")) { snprintf (string, 81, "%-8s= %20u / %-s ", field, va_arg (argp, unsigned),comment); goto found_it; }58 if (!strcmp (mode, "%lu")) { snprintf (string, 81, "%-8s= %20lu / %-s ", field, va_arg (argp, unsigned long), comment); goto found_it; }59 if (!strcmp (mode, "%llu")) { snprintf (string, 81, "%-8s= %20llu / %-s ", field, va_arg (argp, unsigned long long), comment); goto found_it; }60 if (!strcmp (mode, "%Lu")) { snprintf (string, 81, "%-8s= %20llu / %-s ", field, va_arg (argp, unsigned long long), comment); goto found_it; }61 if (!strcmp (mode, "%hd")) { snprintf (string, 81, "%-8s= %20d / %-s ", field, va_arg (argp, int),comment); goto found_it; }62 if (!strcmp (mode, "%f")) { snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double),comment); goto found_it; }63 if (!strcmp (mode, "%lf")) { snprintf (string, 81, "%-8s= %20.10f / %-s ", field, va_arg (argp, double),comment); goto found_it; }64 if (!strcmp (mode, "%e")) { snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double),comment); goto found_it; }65 if (!strcmp (mode, "%le")) { snprintf (string, 81, "%-8s= %20.10E / %-s ", field, va_arg (argp, double),comment); goto found_it; }66 if (!strcmp (mode, "%g")) { snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double),comment); goto found_it; }67 if (!strcmp (mode, "%lg")) { snprintf (string, 81, "%-8s= %20.10G / %-s ", field, va_arg (argp, double),comment); goto found_it; }68 if (!strcmp (mode, "%jd")) { snprintf (string, 81, "%-8s= %20jd / %-s ", field, va_arg (argp, intmax_t),comment); goto found_it; }55 if (!strcmp (mode, "%d")) { snprintf (string, 200, "%-8s= %20d / %-s ", field, va_arg (argp, int), comment); goto found_it; } 56 if (!strcmp (mode, "%ld")) { snprintf (string, 200, "%-8s= %20ld / %-s ", field, va_arg (argp, long), comment); goto found_it; } 57 if (!strcmp (mode, "%lld")) { snprintf (string, 200, "%-8s= %20lld / %-s ", field, va_arg (argp, long long), comment); goto found_it; } 58 if (!strcmp (mode, "%Ld")) { snprintf (string, 200, "%-8s= %20lld / %-s ", field, va_arg (argp, long long), comment); goto found_it; } 59 if (!strcmp (mode, "%u")) { snprintf (string, 200, "%-8s= %20u / %-s ", field, va_arg (argp, unsigned), comment); goto found_it; } 60 if (!strcmp (mode, "%lu")) { snprintf (string, 200, "%-8s= %20lu / %-s ", field, va_arg (argp, unsigned long), comment); goto found_it; } 61 if (!strcmp (mode, "%llu")) { snprintf (string, 200, "%-8s= %20llu / %-s ", field, va_arg (argp, unsigned long long), comment); goto found_it; } 62 if (!strcmp (mode, "%Lu")) { snprintf (string, 200, "%-8s= %20llu / %-s ", field, va_arg (argp, unsigned long long), comment); goto found_it; } 63 if (!strcmp (mode, "%hd")) { snprintf (string, 200, "%-8s= %20d / %-s ", field, va_arg (argp, int), comment); goto found_it; } 64 if (!strcmp (mode, "%f")) { snprintf (string, 200, "%-8s= %20.10f / %-s ", field, va_arg (argp, double), comment); goto found_it; } 65 if (!strcmp (mode, "%lf")) { snprintf (string, 200, "%-8s= %20.10f / %-s ", field, va_arg (argp, double), comment); goto found_it; } 66 if (!strcmp (mode, "%e")) { snprintf (string, 200, "%-8s= %20.10E / %-s ", field, va_arg (argp, double), comment); goto found_it; } 67 if (!strcmp (mode, "%le")) { snprintf (string, 200, "%-8s= %20.10E / %-s ", field, va_arg (argp, double), comment); goto found_it; } 68 if (!strcmp (mode, "%g")) { snprintf (string, 200, "%-8s= %20.10G / %-s ", field, va_arg (argp, double), comment); goto found_it; } 69 if (!strcmp (mode, "%lg")) { snprintf (string, 200, "%-8s= %20.10G / %-s ", field, va_arg (argp, double), comment); goto found_it; } 70 if (!strcmp (mode, "%jd")) { snprintf (string, 200, "%-8s= %20jd / %-s ", field, va_arg (argp, intmax_t), comment); goto found_it; } 69 71 70 72 /* string value. Quotes must be at least 8 chars apart */ … … 72 74 char *ptr = va_arg (argp, char *); 73 75 if (!ptr) goto invalid; 74 strncpy (data, ptr, 68);75 snprintf (string, 81, "%-8s= '%-8s' / %-s ", field, data, comment);76 strncpy_nowarn (data, ptr, 68); 77 snprintf (string, 200, "%-8s= '%-8s' / %-s ", field, data, comment); 76 78 goto found_it; 77 79 } … … 83 85 84 86 found_it: 85 strncpy (p, string, 80);87 memcpy (p, string, 80); // do not use strncpy_nowarn: do NOT set last byte to NULL 86 88 va_end (argp); 87 89 return (TRUE); … … 94 96 /* this function is extremely similar to gfits_print, except it allows for changing an existing field. */ 95 97 96 char comment[82], string[ 82], data[82];98 char comment[82], string[200], data[82]; 97 99 char *p, *qs, *qe; 98 100 va_list argp; … … 100 102 va_start (argp, N); 101 103 bzero (data, 82); 102 bzero (string, 82);103 104 bzero (comment, 82); 105 bzero (string, 200); 104 106 105 107 if (mode[0] != '%') { … … 132 134 qe += 3; 133 135 qe = MIN (p + 80, qe); 134 strncpy (comment, qe, p + 80 - qe);136 strncpy_nowarn (comment, qe, p + 80 - qe); 135 137 } 136 138 gfits_pad_ending (comment, 0x20, 82); /* comment must contain spaces to the end */ … … 139 141 if (!strcmp (mode, "%t")) { 140 142 if (va_arg (argp, int)) 141 snprintf (string, 81, "%-8s= %18s T / %-s ", field, " ", comment);143 snprintf (string, 200, "%-8s= %18s T / %-s ", field, " ", comment); 142 144 else 143 snprintf (string, 81, "%-8s= %18s F / %-s ", field, " ", comment);145 snprintf (string, 200, "%-8s= %18s F / %-s ", field, " ", comment); 144 146 } 145 147 … … 148 150 char *ptr = va_arg (argp, char *); 149 151 if (!ptr) goto invalid; 150 strncpy (data, ptr, 71);151 snprintf (string, 81, "%-8s %-71s", field, data);152 strncpy_nowarn (data, ptr, 71); 153 snprintf (string, 200, "%-8s %-71s", field, data); 152 154 } 153 155 … … 161 163 if (qs[-1] == 0x27) qs --; 162 164 163 strncpy (data, qs, MAX (MIN (qe - qs, 71), 0));165 strncpy_nowarn (data, qs, MAX (MIN (qe - qs, 71), 0)); 164 166 165 167 char *ptr = va_arg (argp, char *); 166 168 if (!ptr) goto invalid; 167 strncpy (comment, ptr, 80);169 strncpy_nowarn (comment, ptr, 80); 168 170 gfits_pad_ending (comment, 0x20, 82); /* comment must contain spaces to the end */ 169 snprintf (string, 81, "%-8s= %s / %-s", field, data, comment);171 snprintf (string, 200, "%-8s= %s / %-s", field, data, comment); 170 172 /* this will keep the original line, but truncate the comment */ 171 173 } 172 174 173 strncpy (p, string, 80);175 memcpy (p, string, 80); // do not use strncpy_nowarn: do NOT set last byte to NULL 174 176 va_end (argp); 175 177 return (TRUE);
Note:
See TracChangeset
for help on using the changeset viewer.
