IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 27, 2016, 11:18:36 AM (10 years ago)
Author:
eugene
Message:

trying to catch memory corruption by being extra pedantic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/table/F_set_column.c

    r38553 r39324  
    11# include <ohana.h>
    22# include <gfitsio.h>
     3# define OHANA_MEMCHECK 0
    34
    45# define SWAP_NONE
     
    3435  double Bscale, Bzero;
    3536
     37# if (OHANA_MEMCHECK)
     38  memset (tlabel,  0x7f, 256);
     39  memset (field,   0x7f, 256);
     40  memset (format,  0x7f, 256);
     41  memset (type,    0x7f, 64);
     42  memset (tmpline, 0x7f, 64);
     43
     44  ohana_memcheck_block (data);
     45# endif
     46
    3647  if (label == (char *) NULL) return (FALSE);
    3748  if (label[0] == 0) return (FALSE);
     
    4253  for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
    4354    snprintf (field, 256, "TTYPE%d", i);
    44     gfits_scan (header, field, "%s", 1, tlabel);
     55    if (!gfits_scan (header, field, "%s", 1, tlabel)) return FALSE;
    4556  }
    4657  if (strcasecmp (label, tlabel)) return (FALSE);
     
    5768  }
    5869  snprintf (field, 256, "TFORM%d", N);
    59   gfits_scan (header, field, "%s", 1, format);
     70  if (!gfits_scan (header, field, "%s", 1, format)) return FALSE;
    6071
    6172  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
     
    7283  if (Ny != Nrow) return (FALSE);
    7384
     85  // if we call this function with a null pointer, we are only validating the header and allocating the data array
     86  if (!data) return TRUE;
     87
    7488  /* scan columns to find insert point */
    7589  Nstart = 0;
    7690  for (i = 1; i < N; i++) {
    7791    snprintf (field, 256, "TFORM%d", i);
    78     gfits_scan (header, field, "%s", 1, format);
     92    if (!gfits_scan (header, field, "%s", 1, format)) return FALSE;
    7993    gfits_bintable_format (format, tmpline, &Nv, &Nb);
    8094    Nstart += Nv*Nb;
     
    86100  Pin = data;
    87101  Pout = array;
     102
    88103  // does it makes sense to scale 'char' data?
    89104  if (!strcmp (type, "char")) {
     
    92107    }
    93108  }
     109
    94110  if (!strcmp (type, "byte")) {
    95111    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     
    97113    }
    98114  }
     115
    99116  if (!strcmp (type, "short")) {
    100117    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     
    105122    } 
    106123  }
     124 
    107125  if (!strcmp (type, "int")) {
    108126    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     
    113131    }
    114132  }
     133
    115134  if (!strcmp (type, "int64_t")) {
    116135    // XXX 64 bit int operations with Bzero & Bscale are inaccurate even with doubles
     
    131150    }
    132151  }
     152
    133153  if (!strcmp (type, "float")) {
    134154    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     
    139159    }
    140160  }
     161
    141162  if (!strcmp (type, "double")) {
    142163    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     
    179200  }
    180201
     202# if (OHANA_MEMCHECK)
     203  myAssert ( tlabel[255] == 0x7f, "oops");
     204  myAssert (  field[255] == 0x7f, "oops");
     205  myAssert ( format[255] == 0x7f, "oops");
     206  myAssert (   type[63]  == 0x7f, "oops");
     207  myAssert (tmpline[63]  == 0x7f, "oops");
     208
     209 ohana_memcheck (TRUE);
     210# endif
     211
    181212  free (array);
     213
    182214  return (TRUE);
    183215}
Note: See TracChangeset for help on using the changeset viewer.