IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 8, 2023, 12:17:35 PM (3 years ago)
Author:
eugene
Message:

merge from eam_branches/ipp-20220316. fixes for more pendantic gcc; add opihi memory stats; string vector improvements; use named macros for fixed string lengths

Location:
trunk/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/libfits/header/F_modify.c

    r38441 r42389  
    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
     
    4648    qe += 3;
    4749    qe = MIN (p + 80, qe);
    48     strncpy (comment, qe, p + 80 - qe);
     50    strncpy_nowarn (comment, qe, p + 80 - qe);
    4951  }
    5052  gfits_pad_ending (comment, 0x20, 82);  /* comment must contain spaces to the end */
    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 */
     
    7274    char *ptr = va_arg (argp, char *);
    7375    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);
    7678    goto found_it;
    7779  }
     
    8385
    8486found_it:
    85   strncpy (p, string, 80);
     87  memcpy (p, string, 80); // do not use strncpy_nowarn: do NOT set last byte to NULL
    8688  va_end (argp);
    8789  return (TRUE);
     
    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] != '%') {
     
    132134    qe += 3;
    133135    qe = MIN (p + 80, qe);
    134     strncpy (comment, qe, p + 80 - qe);
     136    strncpy_nowarn (comment, qe, p + 80 - qe);
    135137  }
    136138  gfits_pad_ending (comment, 0x20, 82);  /* comment must contain spaces to the end */
     
    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
     
    148150    char *ptr = va_arg (argp, char *);
    149151    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);
    152154  } 
    153155
     
    161163    if (qs[-1] == 0x27) qs --;
    162164
    163     strncpy (data, qs, MAX (MIN (qe - qs, 71), 0));
     165    strncpy_nowarn (data, qs, MAX (MIN (qe - qs, 71), 0));
    164166
    165167    char *ptr = va_arg (argp, char *);
    166168    if (!ptr) goto invalid;
    167     strncpy (comment, ptr, 80);
     169    strncpy_nowarn (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  }
    172174
    173   strncpy (p, string, 80);
     175  memcpy (p, string, 80); // do not use strncpy_nowarn: do NOT set last byte to NULL
    174176  va_end (argp);
    175177  return (TRUE);
Note: See TracChangeset for help on using the changeset viewer.