IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 31, 2023, 10:55:31 AM (3 years ago)
Author:
eugene
Message:

convert instances of strncpy to strncpy_nowarn (or memcpy in specific cases where ending 0 is not desired)

File:
1 edited

Legend:

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

    r42116 r42343  
    4848    qe += 3;
    4949    qe = MIN (p + 80, qe);
    50     strncpy (comment, qe, p + 80 - qe);
     50    strncpy_nowarn (comment, qe, p + 80 - qe);
    5151  }
    5252  gfits_pad_ending (comment, 0x20, 82);  /* comment must contain spaces to the end */
    5353
    5454  /* write the numeric modes */
    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; }
     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; }
    6060  if (!strcmp (mode, "%lu"))  { snprintf (string, 200, "%-8s= %20lu / %-s ",   field, va_arg (argp, unsigned long),      comment); goto found_it; }
    6161  if (!strcmp (mode, "%llu")) { snprintf (string, 200, "%-8s= %20llu / %-s ",  field, va_arg (argp, unsigned long long), comment); goto found_it; }
    6262  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; }
     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; }
    7171
    7272  /* string value.  Quotes must be at least 8 chars apart */
     
    7474    char *ptr = va_arg (argp, char *);
    7575    if (!ptr) goto invalid;
    76     strncpy (data, ptr, 68);
     76    strncpy_nowarn (data, ptr, 68);
    7777    snprintf (string, 200, "%-8s= '%-8s' / %-s ", field, data, comment);
    7878    goto found_it;
     
    8585
    8686found_it:
    87   strncpy (p, string, 80);
     87  memcpy (p, string, 80); // do not use strncpy_nowarn: do NOT set last byte to NULL
    8888  va_end (argp);
    8989  return (TRUE);
     
    134134    qe += 3;
    135135    qe = MIN (p + 80, qe);
    136     strncpy (comment, qe, p + 80 - qe);
     136    strncpy_nowarn (comment, qe, p + 80 - qe);
    137137  }
    138138  gfits_pad_ending (comment, 0x20, 82);  /* comment must contain spaces to the end */
     
    150150    char *ptr = va_arg (argp, char *);
    151151    if (!ptr) goto invalid;
    152     strncpy (data, ptr, 71);
     152    strncpy_nowarn (data, ptr, 71);
    153153    snprintf (string, 200, "%-8s %-71s", field, data);
    154154  } 
     
    163163    if (qs[-1] == 0x27) qs --;
    164164
    165     strncpy (data, qs, MAX (MIN (qe - qs, 71), 0));
     165    strncpy_nowarn (data, qs, MAX (MIN (qe - qs, 71), 0));
    166166
    167167    char *ptr = va_arg (argp, char *);
    168168    if (!ptr) goto invalid;
    169     strncpy (comment, ptr, 80);
     169    strncpy_nowarn (comment, ptr, 80);
    170170    gfits_pad_ending (comment, 0x20, 82);  /* comment must contain spaces to the end */
    171171    snprintf (string, 200, "%-8s= %s / %-s", field, data, comment);
     
    173173  }
    174174
    175   strncpy (p, string, 80);
     175  memcpy (p, string, 80); // do not use strncpy_nowarn: do NOT set last byte to NULL
    176176  va_end (argp);
    177177  return (TRUE);
Note: See TracChangeset for help on using the changeset viewer.