IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 16, 2022, 4:21:02 PM (4 years ago)
Author:
eugene
Message:

gcc version 9.4 is more strict about input vs output buffer sizes and possible overruns

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20220316/Ohana/src/libfits/header/F_modify.c

    r38441 r42116  
    88  /* this function is extremely similar to gfits_print, except it allows for changing an existing field. */
    99
    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];
    1113  char *p, *qe;
    1214  va_list argp;
     
    1416  va_start (argp, N);
    1517  bzero (data, 82);
    16   bzero (string, 82);
     18  bzero (string, 200);
    1719  bzero (comment, 82);
    1820
     
    5153
    5254  /* 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; }
    6971
    7072  /* string value.  Quotes must be at least 8 chars apart */
     
    7375    if (!ptr) goto invalid;
    7476    strncpy (data, ptr, 68);
    75     snprintf (string, 81, "%-8s= '%-8s' / %-s ", field, data, comment);
     77    snprintf (string, 200, "%-8s= '%-8s' / %-s ", field, data, comment);
    7678    goto found_it;
    7779  }
     
    9496  /* this function is extremely similar to gfits_print, except it allows for changing an existing field. */
    9597
    96   char comment[82], string[82], data[82];
     98  char comment[82], string[200], data[82];
    9799  char *p, *qs, *qe;
    98100  va_list argp;
     
    100102  va_start (argp, N);
    101103  bzero (data, 82);
    102   bzero (string, 82);
    103104  bzero (comment, 82);
     105  bzero (string, 200);
    104106
    105107  if (mode[0] != '%') {
     
    139141  if (!strcmp (mode, "%t")) {
    140142    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);
    142144    else
    143       snprintf (string, 81, "%-8s= %18s F / %-s ", field, " ", comment);
     145      snprintf (string, 200, "%-8s= %18s F / %-s ", field, " ", comment);
    144146  }
    145147
     
    149151    if (!ptr) goto invalid;
    150152    strncpy (data, ptr, 71);
    151     snprintf (string, 81, "%-8s %-71s", field, data);
     153    snprintf (string, 200, "%-8s %-71s", field, data);
    152154  } 
    153155
     
    167169    strncpy (comment, ptr, 80);
    168170    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);
    170172    /* this will keep the original line, but truncate the comment */
    171173  }
Note: See TracChangeset for help on using the changeset viewer.