IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40113


Ignore:
Timestamp:
Aug 9, 2017, 12:47:22 PM (9 years ago)
Author:
eugene
Message:

mostly harmless changes to track down dvopsps segfaults: watch out for Bzero,Bscale in F_set_column.c

Location:
branches/eam_branches/ohana.20170809/src/libfits
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20170809/src/libfits/header/F_H_field.c

    r39926 r40113  
    104104      ptr = buf + 9; // start of following keyword
    105105      if (strncmp (field, ptr, Nfield)) continue;
     106      if (ptr[Nfield + 1] != '=') continue; // the strncmp above will match a longer string which matches the subset of field (e.g., FOO will match FOOBAR and FOO).  test for the following '=' sign
    106107      Nfound ++;
    107108    }
     
    116117      ptr = buf + 9; // start of following keyword
    117118      if (strncmp (field, ptr, Nfield)) continue;
     119      if (ptr[Nfield + 1] != '=') continue; // the strncmp above will match a longer string which matches the subset of field (e.g., FOO will match FOOBAR and FOO).  test for the following '=' sign
    118120      Nfound ++;
    119121      if (Nwant == Nfound) return (ptr);
  • branches/eam_branches/ohana.20170809/src/libfits/header/F_create_H.c

    r34577 r40113  
    11# include <ohana.h>
    22# include <gfitsio.h>
    3 # define NBYTES 2880
    43
    54/******************** fits create header ***********************************/
     
    98  char axis[10];
    109 
    11   header[0].datasize = NBYTES;
     10  header[0].datasize = FT_RECORD_SIZE;
    1211
    13   ALLOCATE (header[0].buffer, char, NBYTES);
     12  ALLOCATE (header[0].buffer, char, FT_RECORD_SIZE);
    1413
    15   for (i = 0; i < NBYTES; i++)
    16     header[0].buffer[i] = ' ';
     14  // XXX this is just slightly suspicious : I am not ending the buffer with a NULL.  if I
     15  // use any string operations on it then they can run past the end.
     16  for (i = 0; i < FT_RECORD_SIZE; i++) header[0].buffer[i] = ' ';
    1717  strncpy (header[0].buffer, "END", 3);
    1818
  • branches/eam_branches/ohana.20170809/src/libfits/header/F_modify.c

    r38441 r40113  
    7272    char *ptr = va_arg (argp, char *);
    7373    if (!ptr) goto invalid;
    74     strncpy (data, ptr, 68);
     74    strncpy (data, ptr, 68); data[68] = 0;
    7575    snprintf (string, 81, "%-8s= '%-8s' / %-s ", field, data, comment);
    7676    goto found_it;
     
    119119      header[0].datasize += FT_RECORD_SIZE;
    120120      REALLOCATE (header[0].buffer, char, header[0].datasize);
     121      /* re-find the "END" marker, in case new memory block is used */
    121122      p = gfits_header_field (header, "END", 1);
    122123      if (p == NULL) return (FALSE);
     
    138139  /* write the boolean mode */
    139140  if (!strcmp (mode, "%t")) {
    140     if (va_arg (argp, int))
    141       snprintf (string, 81, "%-8s= %18s T / %-s ", field, " ", comment);
    142     else
    143       snprintf (string, 81, "%-8s= %18s F / %-s ", field, " ", comment);
     141    // fill data will spaces, null terminated, so snprintf can generate a space-filled block
     142    memset (data, ' ', FT_LINE_LENGTH); data[FT_LINE_LENGTH] = 0;
     143    if (va_arg (argp, int))  {
     144      snprintf (string, 81, "%-8s= %18s T / %-s ", field, data, comment);
     145    } else {
     146      snprintf (string, 81, "%-8s= %18s F / %-s ", field, data, comment);
     147    }
    144148  }
    145149
     
    148152    char *ptr = va_arg (argp, char *);
    149153    if (!ptr) goto invalid;
    150     strncpy (data, ptr, 71);
     154    strncpy (data, ptr, 71); data[71] = 0;
    151155    snprintf (string, 81, "%-8s %-71s", field, data);
    152156  } 
     
    159163    /* keep ' on ends, if there */
    160164    if (qe[0]  == 0x27) qe ++;
    161     if (qs[-1] == 0x27) qs --;
     165    if (qs >= p + 1) {
     166      if (qs[-1] == 0x27) qs --;
     167    }
    162168
    163169    strncpy (data, qs, MAX (MIN (qe - qs, 71), 0));
  • branches/eam_branches/ohana.20170809/src/libfits/header/F_print.c

    r34577 r40113  
    77  /* this function expects one more argument, the value to be written */
    88
    9   static char blank[] = " ";
    10   char string[82], line[80];
     9  char string[82], line[82], blank[82];
    1110  char *p;
    1211  va_list argp; 
     
    4140  memset (p, ' ', FT_LINE_LENGTH);
    4241
     42  memset (blank, ' ', FT_LINE_LENGTH); blank[FT_LINE_LENGTH] = 0;
     43
    4344  /* write the new FITS card, setting the comment to be blank */
    4445  /* in these lines, the value field will expand as needed, forcing out the comment
     
    6768    char *ptr = va_arg (argp, char *);
    6869    if (!ptr) goto invalid;
    69     strcpy (line, ptr);
    70     line[68] = 0;
     70    strncpy (line, ptr, 68); line[68] = 0;
    7171    snprintf (string, 81, "%-8s= '%-8s' / %46s ", field, line, blank);
    7272    goto found_it;
     
    8888  /* this function expects one more argument, the value to be written */
    8989
    90   static char blank[] = " ";
    91   char string[82], line[80];
    92   char *p, a;
     90  char string[82], line[82], blank[82];
     91  char *p;
    9392  va_list argp; 
    9493
    9594  va_start (argp, N);
     95  bzero (line, 82);
     96  bzero (string, 82);
     97  bzero (blank, 82);
    9698 
    9799  if (mode[0] != '%') {
     
    122124  memset (p, ' ', FT_LINE_LENGTH);
    123125
     126  memset (blank, ' ', FT_LINE_LENGTH); blank[FT_LINE_LENGTH] = 0;
     127
    124128  /* write the boolean mode */
    125129  if (!strcmp (mode, "%t")) {
    126     a = va_arg (argp, int);
    127     if (a == 1)
     130    int a = va_arg (argp, int);
     131    if (a == 1) {
    128132      snprintf (string, 81, "%-8s= %18s T / %46s ", field, blank, blank);
    129     else
     133    } else {
    130134      snprintf (string, 81, "%-8s= %18s F / %46s ", field, blank, blank);
     135    }
    131136  }
    132137
  • branches/eam_branches/ohana.20170809/src/libfits/header/F_scan.c

    r39324 r40113  
    8989  // XXX is this safe for 64bit off_t and 32bit off_t?
    9090  // XXX the problem is that we read FITS files on many machine types: I need to ensure
    91   // that we are portable -- this sseems inconsistent
     91  // that we are portable -- this seems inconsistent
    9292  if (!strcmp (mode, "%jd"))  { *va_arg (argp, intmax_t *)           = value; return (TRUE); }
    9393
     
    168168  /* all others require '=' in column p + 1 + strlen(field) */
    169169  Nfield = strlen (field);
    170   if (p[Nfield + 1] != '=') return (FALSE);
     170  if (p[Nfield + 1] != '=') return (FALSE); // probably redundant since gfits_header_hierarch_field requires this condition
    171171
    172172  /* comment from data line */
  • branches/eam_branches/ohana.20170809/src/libfits/matrix/F_compress_utils.c

    r39457 r40113  
    136136
    137137    int has_extension, has_extname, has_zimage, zimage;
    138     char extname[80], extension[80];
     138    char extname[82], extension[82];
    139139
    140140    has_extension = gfits_scan (header, "XTENSION", "%s", 1, extension);
  • branches/eam_branches/ohana.20170809/src/libfits/matrix/F_uncompress_data.c

    r39457 r40113  
    66# define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); }
    77
     8// *Nout comes in with the number of expected (uncompressed) bytes
     9// *Nout returns the number uncompressed pixels
    810int gfits_uncompress_data (char *zdata, unsigned long Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, unsigned long int *Nout, unsigned long int Nout_alloc, int out_pixsize) {
    911
  • branches/eam_branches/ohana.20170809/src/libfits/table/F_create_T.c

    r38441 r40113  
    4343  }
    4444  table[0].datasize = Nbytes;
     45  table[0].validsize = Nbytes;
    4546  table[0].heap_start = gfits_heap_start (header);
    4647  return (TRUE);
     
    5859    bzero (table[0].buffer, Nbytes);
    5960    table[0].datasize = Nbytes;
     61    table[0].validsize = Nbytes;
    6062    table[0].heap_start = gfits_heap_start (header);
    6163  return (TRUE);
  • branches/eam_branches/ohana.20170809/src/libfits/table/F_create_TH.c

    r38989 r40113  
    11# include <ohana.h>
    22# include <gfitsio.h>
    3 # define NBYTES 2880
    43
    54/* a basic table header (extension) is different from a primary header
     
    1312  char axis[128];
    1413 
    15   header[0].datasize = NBYTES;
     14  header[0].datasize = FT_RECORD_SIZE;
    1615
    1716  myAssert (!header->buffer, "failed to init header or free buffer?");
    18   ALLOCATE (header[0].buffer, char, NBYTES);
     17  ALLOCATE (header[0].buffer, char, FT_RECORD_SIZE);
    1918 
    20   for (i = 0; i < NBYTES; i++)
    21   header[0].buffer[i] = ' ';
     19  for (i = 0; i < FT_RECORD_SIZE; i++) header[0].buffer[i] = ' ';
    2220  strncpy (header[0].buffer, "END", 3);
    2321 
  • branches/eam_branches/ohana.20170809/src/libfits/table/F_define_column.c

    r38553 r40113  
    5656  char type[64], field[64];
    5757 
    58   if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
     58  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE); // *** FUNC : OK
    5959 
    6060  Nfields = 0;
  • branches/eam_branches/ohana.20170809/src/libfits/table/F_set_column.c

    r39993 r40113  
    11# include <ohana.h>
    22# include <gfitsio.h>
    3 # define OHANA_MEMCHECK 0
    4 # define CHECK_MEMBLOCKS 0
     3# define OHANA_MEMCHECK 1
     4# define CHECK_MEMBLOCKS 1
    55
    66# define SWAP_NONE
     
    3333  int Nval, Nbytes, Nstart, Nv, Nb;
    3434  char tlabel[256], field[256], format[256], type[64], tmpline[64];
    35   char *Pin, *Pout, *array;
     35  char *Pin, *Pout;
    3636  double Bscale, Bzero;
    3737
     
    5353# endif
    5454
     55  // fprintf (stderr, "Pin: 0x%08lx, Pout: 0x%08lx, array: 0x%08lx\n", (long int) &Pin, (long int) &Pout, (long int) &array);
     56
    5557  if (label == (char *) NULL) return (FALSE);
    5658  if (label[0] == 0) return (FALSE);
     
    6769
    6870  /* interpret format */
     71# if (0)
    6972  snprintf (field, 256, "TSCAL%d", N);
    7073  if (!gfits_scan (header, field, "%lf", 1, &Bscale)) {
     
    7578    Bzero = 0.0;
    7679  }
     80# else
     81    Bscale = 1.0;
     82    Bzero = 0.0;
     83# endif 
     84
    7785  snprintf (field, 256, "TFORM%d", N);
    7886  if (!gfits_scan (header, field, "%s", 1, format)) return FALSE;
     
    107115  /* make duplicate of data with correct type
    108116     byte swap and Bzero/Bscale */
    109   ALLOCATE (array, char, Nbytes*Nval*Nrow);
     117  ALLOCATE_PTR (array, char, Nbytes*Nval*Nrow);
    110118  if (CHECK_MEMBLOCKS) {
    111119    OhanaMemblock *ref = (OhanaMemblock *) array - 1;
    112     fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
     120    // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
    113121    if (!ref->nextBlock && !ref->prevBlock) abort();
     122    if (!ref->size) abort();
    114123  }
    115124
     
    121130  if (CHECK_MEMBLOCKS) {
    122131    OhanaMemblock *ref = (OhanaMemblock *) array - 1;
    123     fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
     132    // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
    124133    if (!ref->nextBlock && !ref->prevBlock) abort();
    125134  }
     
    213222  if (CHECK_MEMBLOCKS) {
    214223    OhanaMemblock *ref = (OhanaMemblock *) array - 1;
    215     fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
     224    // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
    216225    if (!ref->nextBlock && !ref->prevBlock) abort();
    217226  }
     
    242251  if (CHECK_MEMBLOCKS) {
    243252    OhanaMemblock *ref = (OhanaMemblock *) array - 1;
    244     fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
     253    // fprintf (stderr, "ref: 0x%08lx, array: 0x%08lx, size: %zd, (%s@%d : %s), freed: %1d, Nalloc: %d\n", (long int) ref, (long int) array, ref->size, ref->file, ref->line, ref->func, ref->freed, ref->Nalloc);
    245254    if (!ref->nextBlock && !ref->prevBlock) abort();
    246255  }
  • branches/eam_branches/ohana.20170809/src/libfits/table/F_table_format.c

    r39399 r40113  
    33
    44/***********************/
    5 // get the format of a table column
     5// get the format of a table column (see comment block below)
    66// Nval : number of joined columns
    77// Nbytes : width of column
     
    8686   
    8787   all can be preceeded by integer N which specified number
    88    of entries in array
     88   of entries in array:
     89
     90   1L == L
     91   2L
     92   3E, etc
    8993*/
    9094
  • branches/eam_branches/ohana.20170809/src/libfits/table/F_uncompress_T.c

    r39457 r40113  
    267267      unsigned long int Nrows = (row == Ntile - 1) ? ztilelast : ztilelen;
    268268      unsigned long int Nraw = Nrows*fields[i].Nvalues*fields[i].pixsize; // expected number of bytes
     269      unsigned long int Npix_expect = Nrows*fields[i].Nvalues; // expected number of pixels
     270
     271      myAssert (Nraw <= Nraw_alloc, "bad size");
    269272      if (!gfits_uncompress_data (zdata, Nzdata, fields[i].zctype, NULL, NULL, 0, raw, &Nraw, Nraw_alloc, fields[i].pixsize)) ESCAPE;
     273      myAssert (Npix_expect == Nraw, "bad size");
    270274
    271275      if (VERBOSE_DUMP) {
Note: See TracChangeset for help on using the changeset viewer.