IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30442


Ignore:
Timestamp:
Jan 31, 2011, 2:39:33 PM (15 years ago)
Author:
eugene
Message:

use snprintf to avoid buffer overflows

Location:
branches/eam_branches/ipp-20101205/Ohana/src/kapa2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/Ohana/src/kapa2/include/prototypes.h

    r29938 r30442  
    175175void          DrawBitmap          PROTO((Graphic *graphic, int x, int y, int dx, int dy, char *bitmap, int mode));
    176176void          CrossHairs          PROTO((Graphic *graphic, Picture *image));
    177 void          hh_hms              PROTO((char *line, double ra, double dec, char sep));
     177void          hh_hms              PROTO((char *line, double ra, double dec, char sep, int Nchar));
    178178
    179179int           SetColormap         PROTO((char *name));
  • branches/eam_branches/ipp-20101205/Ohana/src/kapa2/src/UpdateStatusBox.c

    r29539 r30442  
    2020 
    2121    bzero (line, 100);
    22     sprintf (line, "(%d x %d) @ %d                                         ",
     22    snprintf (line, 100, "(%d x %d) @ %d                                         ",
    2323             image[0].picture.dx, image[0].picture.dy, image[0].picture.expand);
    2424    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
     
    2626   
    2727    bzero (line, 100);
    28     sprintf (line, "%-25s", image[0].image[0].file);
     28    snprintf (line, 100, "%-25s", image[0].image[0].file);
    2929    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    3030                 image[0].text_x + PAD1, image[0].text_y + 5*textpad + 5*PAD1, line, strlen(line));
    3131   
    3232    bzero (line, 100);
    33     sprintf (line, "(%s)                                          ", image[0].image[0].name);
     33    snprintf (line, 100, "(%s)                                          ", image[0].image[0].name);
    3434    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    3535                 image[0].text_x + PAD1, image[0].text_y + 6*textpad + 6*PAD1, line, 25);
     
    4545
    4646  if (image[0].HexValue) {
    47     sprintf (line, "%04x", (int) z);
     47      snprintf (line, 100, "%04x", (int) z);
    4848  } else {
    49     sprintf (line, "%22.3f", z);
     49      snprintf (line, 100, "%22.3f", z);
    5050  }
    5151  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
     
    5353 
    5454  bzero (line, 100);
    55   sprintf (line, "%10.2f %10.2f", x, y);
     55  snprintf (line, 100, "%10.2f %10.2f", x, y);
    5656  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    5757               image[0].text_x + PAD1, image[0].text_y + 2*textpad + 2*PAD1, line, strlen(line));
     
    5959  bzero (line, 100);
    6060  if (image[0].DecimalDegrees) {
    61     sprintf (line, "%10.6f %10.6f", ra, dec);
     61    snprintf (line, 100, "%10.6f %10.6f", ra, dec);
    6262  } else {
    63     hh_hms (line, ra, dec, ':');
     63    hh_hms (line, ra, dec, ':', 100);
    6464  }
     65
    6566  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    6667               image[0].text_x + PAD1, image[0].text_y + 3*textpad + 3*PAD1, line, strlen(line));
  • branches/eam_branches/ipp-20101205/Ohana/src/kapa2/src/hh_hms.c

    r13320 r30442  
    11# include "Ximage.h"
    22
    3 void hh_hms (char *line, double ra, double dec, char sep) {
     3void hh_hms (char *line, double ra, double dec, char sep, int Nchar) {
    44
    55  int h, m, flag;
     
    1313  s = 3600*(ra - h - m / 60.0);
    1414  if (flag > 0)
    15     sprintf (line, " %02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
     15    snprintf (line, Nchar, " %02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
    1616  else
    17     sprintf (line, "-%02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
     17    snprintf (line, Nchar, "-%02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
    1818 
    1919  flag = SIGN(dec);
     
    2323  s = 3600*(dec - h - m / 60.0);
    2424  if (flag > 0)
    25     sprintf (&line[13], " %02d%c%02d%c%04.1f", h, sep, m, sep, s);
     25    snprintf (&line[13], Nchar, " %02d%c%02d%c%04.1f", h, sep, m, sep, s);
    2626  else
    27     sprintf (&line[13], "-%02d%c%02d%c%04.1f", h, sep, m, sep, s);
     27    snprintf (&line[13], Nchar, "-%02d%c%02d%c%04.1f", h, sep, m, sep, s);
    2828}
Note: See TracChangeset for help on using the changeset viewer.