From: <and...@us...> - 2009-02-08 22:05:59
|
Revision: 9475 http://plplot.svn.sourceforge.net/plplot/?rev=9475&view=rev Author: andrewross Date: 2009-02-08 22:05:56 +0000 (Sun, 08 Feb 2009) Log Message: ----------- Use #define's to set the size of various char buffers to ensure that the values used to define the buffers are the same as those used in calls to snprintf. Modified Paths: -------------- trunk/drivers/cairo.c trunk/drivers/get-drv-info.c trunk/drivers/gnome.c trunk/drivers/plmeta.c trunk/drivers/ps.c trunk/drivers/psttf.cc trunk/drivers/tk.c trunk/drivers/xwin.c trunk/include/plplotP.h trunk/src/plbox.c trunk/src/plcont.c trunk/src/plcore.c trunk/src/plctrl.c trunk/src/plfreetype.c Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/drivers/cairo.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -157,8 +157,11 @@ "PLPLOT_FREETYPE_SYMBOL_FAMILY" }; -char familyLookup[NPANGOLOOKUP][1024]; +#define FAMILY_LOOKUP_LEN 1024 +char familyLookup[NPANGOLOOKUP][FAMILY_LOOKUP_LEN]; +#define TAG_LEN 200 + const char *weightLookup[2] = { "normal", "bold" @@ -566,20 +569,20 @@ { int i; unsigned char fontFamily, fontStyle, fontWeight; - char openTag[200]; + char openTag[TAG_LEN]; /* Generate the font info for the open tag & concatenate this onto the markup string. */ plP_fci2hex(fci, &fontFamily, PL_FCI_FAMILY); plP_fci2hex(fci, &fontStyle, PL_FCI_STYLE); plP_fci2hex(fci, &fontWeight, PL_FCI_WEIGHT); - snprintf(openTag, 200, "<span font_desc=\"%s %.2f\" ", familyLookup[fontFamily], fontSize); + snprintf(openTag, TAG_LEN, "<span font_desc=\"%s %.2f\" ", familyLookup[fontFamily], fontSize); strncat(pangoMarkupString, openTag, MAX_MARKUP_LEN); - snprintf(openTag, 200, "style=\"%s\" ", styleLookup[fontStyle]); + snprintf(openTag, TAG_LEN, "style=\"%s\" ", styleLookup[fontStyle]); strncat(pangoMarkupString, openTag, MAX_MARKUP_LEN); - snprintf(openTag, 200, "weight=\"%s\">", weightLookup[fontWeight]); + snprintf(openTag, TAG_LEN, "weight=\"%s\">", weightLookup[fontWeight]); strncat(pangoMarkupString, openTag, MAX_MARKUP_LEN); /* Move to the right sub/super-script level */ @@ -686,10 +689,10 @@ This was copied from the psttf driver. */ for(i=0;i<NPANGOLOOKUP;i++){ if((a = getenv(envFamilyLookup[i])) != NULL){ - strncpy(familyLookup[i],a,1024); + strncpy(familyLookup[i],a,FAMILY_LOOKUP_LEN); } else { - strncpy(familyLookup[i],defaultFamilyLookup[i],1024); + strncpy(familyLookup[i],defaultFamilyLookup[i],FAMILY_LOOKUP_LEN); } } Modified: trunk/drivers/get-drv-info.c =================================================================== --- trunk/drivers/get-drv-info.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/drivers/get-drv-info.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -31,6 +31,9 @@ #include <signal.h> #include <stdlib.h> +#define SYM_LEN 300 +#define DRVSPEC_LEN 400 + /* SEGV signal handler */ RETSIGTYPE catch_segv (int sig) @@ -43,9 +46,9 @@ main (int argc, char* argv[]) { lt_dlhandle dlhand; - char sym[300]; + char sym[SYM_LEN]; char* drvnam = argv[1]; - char drvspec[ 400 ]; + char drvspec[ DRVSPEC_LEN ]; char** info; /* Establish a handler for SIGSEGV signals. */ @@ -53,9 +56,9 @@ lt_dlinit (); #ifdef LTDL_WIN32 - snprintf( drvspec, 400, "%s", drvnam ); + snprintf( drvspec, DRVSPEC_LEN, "%s", drvnam ); #else - snprintf( drvspec, 400, "%s/%s", plGetDrvDir (), drvnam ); + snprintf( drvspec, DRVSPEC_LEN, "%s/%s", plGetDrvDir (), drvnam ); #endif /* LTDL_WIN32 */ dlhand = lt_dlopenext (drvspec); if (dlhand == NULL) { @@ -63,7 +66,7 @@ "libltdl error: %s\n", drvspec, lt_dlerror ()); return 1; } - snprintf (sym, 300, "plD_DEVICE_INFO_%s", drvnam); + snprintf (sym, SYM_LEN, "plD_DEVICE_INFO_%s", drvnam); info = (char **) lt_dlsym (dlhand, sym); if (info != NULL) { printf ("%s", *info); Modified: trunk/drivers/gnome.c =================================================================== --- trunk/drivers/gnome.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/drivers/gnome.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -67,6 +67,8 @@ /* Magnification factor for the PLplot physical dimensions */ #define MAG_FACTOR 10 +#define BUFFER_LEN 128 + #ifndef ABS #define ABS(x) ((x < 0) ? (-(x)) : (x)) #endif @@ -248,7 +250,7 @@ static guint dragging; guint move; GdkCursor *cursor; - char buffer[128]; + char buffer[BUFFER_LEN]; PLGraphicsIn* gin = &(page->gin); ItemColor* color; GnomeCanvasItem* item_at_cursor; @@ -345,10 +347,10 @@ buffer[0] = '\0'; else if (color->cmap == 0) - snprintf (buffer, 128, " x = %f y = %f color = %d (cmap0)", + snprintf (buffer, BUFFER_LEN, " x = %f y = %f color = %d (cmap0)", gin->wX, gin->wY, (int) color->color); else - snprintf (buffer, 128, " x = %f y = %f color = %f (cmap1)", + snprintf (buffer, BUFFER_LEN, " x = %f y = %f color = %f (cmap1)", gin->wX, gin->wY, color->color); /*// FIXME : Terrible global variable hack*/ @@ -540,7 +542,7 @@ GnomeCanvasPoints* points; guint np; guint32 loclinecolor; - char buffer[32]; + char buffer[BUFFER_LEN]; dev = pls->dev; page = g_malloc (sizeof (GnomePLdevPage)); @@ -700,7 +702,7 @@ gtk_notebook_set_show_tabs (dev->notebook, (np > 0)); - snprintf (buffer, 32, "Page %d", np+1); + snprintf (buffer, BUFFER_LEN, "Page %d", np+1); gtk_notebook_append_page (dev->notebook, GTK_WIDGET (page->sw), gtk_label_new (buffer)); Modified: trunk/drivers/plmeta.c =================================================================== --- trunk/drivers/plmeta.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/drivers/plmeta.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -67,7 +67,8 @@ /* Used for constructing error messages */ -static char buffer[256]; +#define BUFFER_LEN 256 +static char buffer[BUFFER_LEN]; /* Function prototypes */ @@ -410,7 +411,7 @@ /* The forward byte offset is located exactly 7 bytes after the BOP */ fwbyte_offset = dev->lp_offset + 7; if (pl_fsetpos(file, &fwbyte_offset)) { - snprintf(buffer, 256, "UpdatePrevPagehdr (plmeta.c): fsetpos to fwbyte_offset (%d) failed", + snprintf(buffer, BUFFER_LEN, "UpdatePrevPagehdr (plmeta.c): fsetpos to fwbyte_offset (%d) failed", (int) fwbyte_offset); plexit(buffer); } @@ -435,7 +436,7 @@ #ifdef DEBUG if (pl_fsetpos(file, &fwbyte_offset)) { - snprintf(buffer, 256, "UpdatePrevPagehdr (plmeta.c): fsetpos to fwbyte_offset (%d) failed", + snprintf(buffer, BUFFER_LEN, "UpdatePrevPagehdr (plmeta.c): fsetpos to fwbyte_offset (%d) failed", (int) fwbyte_offset); plexit(buffer); } @@ -450,7 +451,7 @@ /* Return to current page offset */ if (pl_fsetpos(file, &cp_offset)) { - snprintf(buffer, 256, "UpdatePrevPagehdr (plmeta.c): fsetpos to cp_offset (%d) failed", + snprintf(buffer, BUFFER_LEN, "UpdatePrevPagehdr (plmeta.c): fsetpos to cp_offset (%d) failed", (int) cp_offset); plexit(buffer); } @@ -478,7 +479,7 @@ (int) cp_offset, (int) dev->lp_offset); if (pl_fsetpos(file, &dev->index_offset)) { - snprintf(buffer, 256, "UpdateIndex (plmeta.c): fsetpos to index_offset (%d) failed", + snprintf(buffer, BUFFER_LEN, "UpdateIndex (plmeta.c): fsetpos to index_offset (%d) failed", (int) dev->index_offset); plexit(buffer); } @@ -490,7 +491,7 @@ (int) dev->lp_offset, (int) cp_offset); if (pl_fsetpos(file, &cp_offset)) { - snprintf(buffer, 256, "UpdateIndex (plmeta.c): fsetpos to cp_offset (%d) failed", + snprintf(buffer, BUFFER_LEN, "UpdateIndex (plmeta.c): fsetpos to cp_offset (%d) failed", (int) cp_offset); plexit(buffer); } Modified: trunk/drivers/ps.c =================================================================== --- trunk/drivers/ps.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/drivers/ps.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -65,7 +65,8 @@ static void proc_str (PLStream *, EscText *); static void esc_purge (unsigned char *, unsigned char *); -static char outbuf[128]; +#define OUTBUF_LEN 128 +static char outbuf[OUTBUF_LEN]; static int text = 1; static int color; static int hrshsym = 1; @@ -408,7 +409,7 @@ else putc(' ', OF); - snprintf(outbuf, 128, "%d %d D", x2, y2); + snprintf(outbuf, OUTBUF_LEN, "%d %d D", x2, y2); dev->ptcnt++; pls->linepos += 12; } @@ -417,9 +418,9 @@ pls->linepos = 0; if (x1 == x2 && y1 == y2) /* must be a single dot, draw a circle */ - snprintf(outbuf, 128, "%d %d A", x1, y1); + snprintf(outbuf, OUTBUF_LEN, "%d %d A", x1, y1); else - snprintf(outbuf, 128, "%d %d M %d %d D", x1, y1, x2, y2); + snprintf(outbuf, OUTBUF_LEN, "%d %d M %d %d D", x1, y1, x2, y2); dev->llx = MIN(dev->llx, x1); dev->lly = MIN(dev->lly, y1); dev->urx = MAX(dev->urx, x1); @@ -657,7 +658,7 @@ /* First time through start with a x y moveto */ if (n == 0) { - snprintf(outbuf, 128, "N %d %d M", x, y); + snprintf(outbuf, OUTBUF_LEN, "N %d %d M", x, y); dev->llx = MIN(dev->llx, x); dev->lly = MIN(dev->lly, y); dev->urx = MAX(dev->urx, x); @@ -676,7 +677,7 @@ pls->bytecnt++; - snprintf(outbuf, 128, "%d %d D", x, y); + snprintf(outbuf, OUTBUF_LEN, "%d %d D", x, y); dev->llx = MIN(dev->llx, x); dev->lly = MIN(dev->lly, y); dev->urx = MAX(dev->urx, x); Modified: trunk/drivers/psttf.cc =================================================================== --- trunk/drivers/psttf.cc 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/drivers/psttf.cc 2009-02-08 22:05:56 UTC (rev 9475) @@ -72,7 +72,8 @@ static void proc_str (PLStream *, EscText *); static void esc_purge (char *, char *); -static char outbuf[128]; +#define OUTBUF_LEN 128 +static char outbuf[OUTBUF_LEN]; static int text = 1; static int color; static int hrshsym = 0; @@ -97,7 +98,8 @@ "PLPLOT_FREETYPE_SYMBOL_FAMILY" }; -char FamilyLookup[N_Pango_Lookup][1024]; +#define FAMILY_LOOKUP_LEN 1024 +char FamilyLookup[N_Pango_Lookup][FAMILY_LOOKUP_LEN]; const FontWeight WeightLookup[2] = { NORMAL_WEIGHT, @@ -283,10 +285,10 @@ // or defaults. for (i=0;i<N_Pango_Lookup;i++) { if ( (a = getenv(EnvFamilyLookup[i])) != NULL ) { - strncpy(FamilyLookup[i],a,1024); + strncpy(FamilyLookup[i],a,FAMILY_LOOKUP_LEN); } else { - strncpy(FamilyLookup[i],DefaultFamilyLookup[i],1024); + strncpy(FamilyLookup[i],DefaultFamilyLookup[i],FAMILY_LOOKUP_LEN); } } @@ -471,7 +473,7 @@ else doc->osBody() << ' '; - snprintf(outbuf, 128, "%d %d D", x2, y2); + snprintf(outbuf, OUTBUF_LEN, "%d %d D", x2, y2); dev->ptcnt++; pls->linepos += 12; } @@ -480,9 +482,9 @@ pls->linepos = 0; if (x1 == x2 && y1 == y2) /* must be a single dot, draw a circle */ - snprintf(outbuf, 128, "%d %d A", x1, y1); + snprintf(outbuf, OUTBUF_LEN, "%d %d A", x1, y1); else - snprintf(outbuf, 128, "%d %d M %d %d D", x1, y1, x2, y2); + snprintf(outbuf, OUTBUF_LEN, "%d %d M %d %d D", x1, y1, x2, y2); dev->llx = MIN(dev->llx, x1); dev->lly = MIN(dev->lly, y1); dev->urx = MAX(dev->urx, x1); @@ -734,7 +736,7 @@ /* First time through start with a x y moveto */ if (n == 0) { - snprintf(outbuf, 128, "N %d %d M", x, y); + snprintf(outbuf, OUTBUF_LEN, "N %d %d M", x, y); dev->llx = MIN(dev->llx, x); dev->lly = MIN(dev->lly, y); dev->urx = MAX(dev->urx, x); @@ -753,7 +755,7 @@ pls->bytecnt++; - snprintf(outbuf, 128, "%d %d D", x, y); + snprintf(outbuf, OUTBUF_LEN, "%d %d D", x, y); dev->llx = MIN(dev->llx, x); dev->lly = MIN(dev->lly, y); dev->urx = MAX(dev->urx, x); Modified: trunk/drivers/tk.c =================================================================== --- trunk/drivers/tk.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/drivers/tk.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -79,6 +79,9 @@ #define LOCATE_INVOKED_VIA_API 1 #define LOCATE_INVOKED_VIA_DRIVER 2 +#define STR_LEN 10 +#define CMD_LEN 100 + /* A handy command wrapper */ #define tk_wr(code) \ @@ -641,7 +644,7 @@ tk_di(PLStream *pls) { TkDev *dev = (TkDev *) pls->dev; - char str[10]; + char str[STR_LEN]; dbug_enter("tk_di"); @@ -659,7 +662,7 @@ /* Change orientation */ if (pls->difilt & PLDI_ORI) { - snprintf(str, 10, "%f", pls->diorot); + snprintf(str, STR_LEN, "%f", pls->diorot); Tcl_SetVar(dev->interp, "rot", str, 0); server_cmd( pls, "$plwidget cmd plsetopt -ori $rot", 1 ); @@ -669,13 +672,13 @@ /* Change window into plot space */ if (pls->difilt & PLDI_PLT) { - snprintf(str, 10, "%f", pls->dipxmin); + snprintf(str, STR_LEN, "%f", pls->dipxmin); Tcl_SetVar(dev->interp, "xl", str, 0); - snprintf(str, 10, "%f", pls->dipymin); + snprintf(str, STR_LEN, "%f", pls->dipymin); Tcl_SetVar(dev->interp, "yl", str, 0); - snprintf(str, 10, "%f", pls->dipxmax); + snprintf(str, STR_LEN, "%f", pls->dipxmax); Tcl_SetVar(dev->interp, "xr", str, 0); - snprintf(str, 10, "%f", pls->dipymax); + snprintf(str, STR_LEN, "%f", pls->dipymax); Tcl_SetVar(dev->interp, "yr", str, 0); server_cmd( pls, "$plwidget cmd plsetopt -wplt $xl,$yl,$xr,$yr", 1 ); @@ -685,13 +688,13 @@ /* Change window into device space */ if (pls->difilt & PLDI_DEV) { - snprintf(str, 10, "%f", pls->mar); + snprintf(str, STR_LEN, "%f", pls->mar); Tcl_SetVar(dev->interp, "mar", str, 0); - snprintf(str, 10, "%f", pls->aspect); + snprintf(str, STR_LEN, "%f", pls->aspect); Tcl_SetVar(dev->interp, "aspect", str, 0); - snprintf(str, 10, "%f", pls->jx); + snprintf(str, STR_LEN, "%f", pls->jx); Tcl_SetVar(dev->interp, "jx", str, 0); - snprintf(str, 10, "%f", pls->jy); + snprintf(str, STR_LEN, "%f", pls->jy); Tcl_SetVar(dev->interp, "jy", str, 0); server_cmd( pls, "$plwidget cmd plsetopt -mar $mar", 1 ); @@ -1324,7 +1327,7 @@ plwindow_init(PLStream *pls) { TkDev *dev = (TkDev *) pls->dev; - char command[100]; + char command[CMD_LEN]; unsigned int bg; dbug_enter("plwindow_init"); @@ -1346,7 +1349,7 @@ bg = pls->cmap0[0].b | (pls->cmap0[0].g << 8) | (pls->cmap0[0].r << 16); if (bg > 0) { - snprintf(command, 100, "$plwidget configure -plbg #%06x", bg); + snprintf(command, CMD_LEN, "$plwidget configure -plbg #%06x", bg); server_cmd( pls, command, 0 ); } @@ -1368,12 +1371,12 @@ /* color map options */ if (pls->ncol0) { - snprintf(command, 100, "$plwidget cmd plsetopt -ncol0 %d", pls->ncol0); + snprintf(command, CMD_LEN, "$plwidget cmd plsetopt -ncol0 %d", pls->ncol0); server_cmd( pls, command, 0 ); } if (pls->ncol1) { - snprintf(command, 100, "$plwidget cmd plsetopt -ncol1 %d", pls->ncol1); + snprintf(command, CMD_LEN, "$plwidget cmd plsetopt -ncol1 %d", pls->ncol1); server_cmd( pls, command, 0 ); } Modified: trunk/drivers/xwin.c =================================================================== --- trunk/drivers/xwin.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/drivers/xwin.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -112,6 +112,8 @@ #define ROMAP_CMAP1_COLORS 50 #define TC_CMAP1_COLORS 200 +#define HEADER_LEN 1024 + /* Variables to hold RGB components of given colormap. */ /* Used in an ugly hack to get past some X11R5 and TK limitations. */ @@ -1085,7 +1087,7 @@ XSizeHints hint; int x, y; U_INT width, height, border, depth; - char header[1024]; + char header[HEADER_LEN]; dbug_enter("InitMain"); @@ -1129,13 +1131,13 @@ /* Window title */ if (pls->plwindow){ /* allow -plwindow to specify wm decoration name */ - strncpy(header, pls->plwindow, 1024); + strncpy(header, pls->plwindow, HEADER_LEN); } else if(pls->program) { - strncpy(header, pls->program, 1024); /* else program name */ + strncpy(header, pls->program, HEADER_LEN); /* else program name */ } else - strncpy(header,"Plplot",1024); + strncpy(header,"Plplot",HEADER_LEN); /* Window creation */ Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/include/plplotP.h 2009-02-08 22:05:56 UTC (rev 9475) @@ -391,6 +391,9 @@ #define PLPLOT_TCL_ENV "PLPLOT_TCL" #define PLPLOT_HOME_ENV "PLPLOT_HOME" +/* Maximum size for path strings in the plplot code */ +#define PLPLOT_MAX_PATH 1024 + /* * Some stuff that is included (and compiled into) plsym.h * Other modules might want this, so we will "extern" it Modified: trunk/src/plbox.c =================================================================== --- trunk/src/plbox.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/src/plbox.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -25,6 +25,10 @@ #include "plplotP.h" #include "qsastime.h" +#define STRING_LEN 40 +#define FORMAT_LEN 10 +#define TEMP_LEN 30 + static PLFLT xlog[8] = { 0.301030, 0.477121, 0.602060, 0.698970, @@ -656,7 +660,7 @@ PLFLT wx2, PLFLT wy2, PLFLT vmin_in, PLFLT vmax_in, PLFLT tick, PLINT nsub, PLINT nolast, PLINT *digits) { - static char string[40]; + static char string[STRING_LEN]; PLINT lb, ld, lf, li, ll, ln, ls, lt, lu; PLINT major, minor, mode, prec, scale; PLINT i, i1, i2, i3, i4; @@ -773,7 +777,7 @@ tp = tick1 * (1. + floor(vmin / tick1)); for (tn = tp; BETW(tn, vmin, vmax); tn += tick1) { if(BETW(tn, vmin+tcrit, vmax-tcrit)) { - plform(tn, scale, prec, string, 40, ll, lf); + plform(tn, scale, prec, string, STRING_LEN, ll, lf); pos = (vmax_in > vmin_in)? (tn - vmin) / (vmax - vmin): (vmax - tn) / (vmax - vmin); @@ -782,7 +786,7 @@ } *digits = 2; if (!ll && mode) { - snprintf(string, 40, "(x10#u%d#d)", (int) scale); + snprintf(string, STRING_LEN, "(x10#u%d#d)", (int) scale); plxytx(wx1, wy1, wx2, wy2, height, 1.0, 0.5, string); } } @@ -867,7 +871,7 @@ PLFLT wx, PLFLT wy1, PLFLT wy2, PLFLT vmin_in, PLFLT vmax_in, PLFLT tick, PLINT nsub, PLINT *digits) { - static char string[40]; + static char string[STRING_LEN]; PLINT lb, lc, ld, lf, li, ll, lm, ln, ls, lt, lu, lv; PLINT i, mode, prec, scale; PLINT nsub1, lstring; @@ -989,7 +993,7 @@ *digits = 0; tp = tick1 * floor(vmin / tick1); for (tn = tp + tick1; BETW(tn, vmin, vmax); tn += tick1) { - plform(tn, scale, prec, string, 40, ll, lf); + plform(tn, scale, prec, string, STRING_LEN, ll, lf); pos = (vmax_in > vmin_in)? (tn - vmin) / (vmax - vmin): (vmax - tn) / (vmax - vmin); @@ -1003,7 +1007,7 @@ *digits = MAX(*digits, lstring); } if (!ll && mode) { - snprintf(string, 40, "(x10#u%d#d)", (int) scale); + snprintf(string, STRING_LEN, "(x10#u%d#d)", (int) scale); pos = 1.15; height = 0.5; if (ln && !right) { @@ -1192,7 +1196,7 @@ static void label_box(const char *xopt, PLFLT xtick1, const char *yopt, PLFLT ytick1) { - static char string[40]; + static char string[STRING_LEN]; PLBOOL ldx, lfx, lix, llx, lmx, lnx, ltx; PLBOOL ldy, lfy, liy, lly, lmy, lny, lty, lvy; PLFLT vpwxmi, vpwxma, vpwymi, vpwyma; @@ -1249,10 +1253,10 @@ if (ldx) { t = (double) tn; setFromUT(1970,0,1,0,0,t,&tm,0); - strfMJD(string, 40, timefmt, &tm, 0); + strfMJD(string, STRING_LEN, timefmt, &tm, 0); } else { - plform(tn, xscale, xprec, string, 40, llx, lfx); + plform(tn, xscale, xprec, string, STRING_LEN, llx, lfx); } height = lix ? 1.75 : 1.5; pos = (vpwxmax > vpwxmin)? @@ -1271,7 +1275,7 @@ if (!llx && !ldx && xmode) { pos = 1.0; height = 3.2; - snprintf(string, 40, "(x10#u%d#d)", (int) xscale); + snprintf(string, STRING_LEN, "(x10#u%d#d)", (int) xscale); if (lnx) plmtex("b", height, pos, 0.5, string); if (lmx) @@ -1298,10 +1302,10 @@ if (ldy) { t = (double) tn; setFromUT(1970,0,1,0,0,t,&tm,0); - strfMJD(string, 40, timefmt, &tm, 0); + strfMJD(string, STRING_LEN, timefmt, &tm, 0); } else { - plform(tn, yscale, yprec, string, 40, lly, lfy); + plform(tn, yscale, yprec, string, STRING_LEN, lly, lfy); } pos = (vpwymax > vpwymin)? (tn - vpwymi) / (vpwyma - vpwymi): @@ -1334,7 +1338,7 @@ /* Write separate exponential label if mode = 1. */ if (!lly && !ldy && ymode) { - snprintf(string, 40, "(x10#u%d#d)", (int) yscale); + snprintf(string, STRING_LEN, "(x10#u%d#d)", (int) yscale); offset = 0.02; height = 2.0; if (lny) { @@ -1386,8 +1390,8 @@ value = pow(10.0, exponent); if (exponent < 0) { - char form[10]; - snprintf(form, 10, "%%.%df", ABS(exponent)); + char form[FORMAT_LEN]; + snprintf(form, FORMAT_LEN, "%%.%df", ABS(exponent)); snprintf(string, len, form, value); } else { @@ -1406,7 +1410,7 @@ /* Linear */ PLINT setpre, precis; - char form[10], temp[30]; + char form[FORMAT_LEN], temp[TEMP_LEN]; double scale2; plP_gprec(&setpre, &precis); @@ -1422,8 +1426,8 @@ scale2 = pow(10., prec); value = floor((value * scale2) + .5) / scale2; - snprintf(form, 10, "%%.%df", (int) prec); - snprintf(temp, 30, form, value); + snprintf(form, FORMAT_LEN, "%%.%df", (int) prec); + snprintf(temp, TEMP_LEN, form, value); strncpy(string, temp, len); } } Modified: trunk/src/plcont.c =================================================================== --- trunk/src/plcont.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/src/plcont.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -316,7 +316,9 @@ * Obviously there are security issues here that * should be addressed as well. */ - char form[10], tmpstring[15]; +#define FORM_LEN 10 +#define TMPSTRING_LEN 15 + char form[FORM_LEN], tmpstring[TMPSTRING_LEN]; PLINT exponent = 0; PLFLT mant, tmp; @@ -349,9 +351,9 @@ if (mant != 0.0) mant = (int )(mant*pow(10.0, prec-1) + 0.5*mant/fabs(mant))/pow(10.0, prec-1); - snprintf(form, 10, "%%.%df", prec-1); + snprintf(form, FORM_LEN, "%%.%df", prec-1); snprintf(string, len, form, mant); - snprintf(tmpstring, 15, "#(229)10#u%d", exponent); + snprintf(tmpstring, TMPSTRING_LEN, "#(229)10#u%d", exponent); strncat(string, tmpstring, len); if (abs(exponent) < limexp || value == 0.0) { @@ -365,7 +367,7 @@ if (prec < 0) prec = 0; - snprintf(form, 10, "%%.%df", (int) prec); + snprintf(form, FORM_LEN, "%%.%df", (int) prec); snprintf(string, len, form, value); } } Modified: trunk/src/plcore.c =================================================================== --- trunk/src/plcore.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/src/plcore.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -45,6 +45,10 @@ #endif #endif +#define BUFFER_SIZE 80 +#define BUFFER2_SIZE 300 +#define DRVSPEC_SIZE 400 + /*--------------------------------------------------------------------------*\ * Driver Interface * @@ -395,12 +399,12 @@ char *endptr; char *endptr2; - char msgbuf[80]; + char msgbuf[BUFFER_SIZE]; *num = strtoul(text,&endptr,0); if (end != endptr[0]) { - snprintf(msgbuf,80,"text2num: invalid control string detected - %c expected",end); + snprintf(msgbuf,BUFFER_SIZE,"text2num: invalid control string detected - %c expected",end); plwarn(msgbuf); } @@ -677,9 +681,9 @@ char* ptr = utf8_to_ucs4 (string + i, &unichar); #endif if (ptr == NULL) { - char buf[80]; + char buf[BUFFER_SIZE]; strncpy (buf, string, 30); - snprintf (buf, 80, "UTF-8 string is malformed: %s%s", + snprintf (buf, BUFFER_SIZE, "UTF-8 string is malformed: %s%s", buf, strlen (string) > 30 ? "[...]" : ""); plabort (buf); return; @@ -2125,8 +2129,8 @@ static int inBuildTree = 0; if (inited == 0) { - char currdir[256]; - char builddir[256]; + char currdir[PLPLOT_MAX_PATH]; + char builddir[PLPLOT_MAX_PATH]; /* AM: getcwd has a somewhat strange status on Windows, its proper name is _getcwd, this is a problem in the case of DLLs, like with @@ -2136,14 +2140,14 @@ #define getcwd _getcwd #endif - if (getcwd(currdir, 256) == NULL) { + if (getcwd(currdir, PLPLOT_MAX_PATH) == NULL) { pldebug("plInBuildTree():", "Not enough buffer space"); } else { /* The chdir / getcwd call is to ensure we get the physical * path without any symlinks */ /* Ignore error in chdir - build tree may not exist */ if (chdir(BUILD_DIR) == 0) { - if (getcwd(builddir, 256) == NULL) { + if (getcwd(builddir, PLPLOT_MAX_PATH) == NULL) { pldebug("plInBuildTree():", "Not enough buffer space"); } else { @@ -2214,7 +2218,7 @@ int n; #ifdef ENABLE_DYNDRIVERS - char buf[300]; + char buf[BUFFER2_SIZE]; char* drvdir; char *devnam, *devdesc, *devtype, *driver, *tag, *seqstr; int seq; @@ -2253,15 +2257,14 @@ /* Only consider entries that have the ".rc" suffix */ if ((len > 0) && (strcmp (name + len, ".rc") == 0)) { - char path[300]; - char buf[300]; + char path[PLPLOT_MAX_PATH]; FILE* fd; /* Open the driver's info file */ - snprintf (path, 300, "%s/%s", drvdir, name); + snprintf (path, PLPLOT_MAX_PATH, "%s/%s", drvdir, name); fd = fopen (path, "r"); if (fd == NULL) { - snprintf (buf, 300, + snprintf (buf, BUFFER2_SIZE, "plInitDispatchTable: Could not open driver info file %s\n", name); plabort (buf); @@ -2274,7 +2277,7 @@ pldebug ("plInitDispatchTable", "Opened driver info file %s\n", name); - while (fgets (buf, 300, fd) != NULL) + while (fgets (buf, BUFFER2_SIZE, fd) != NULL) { fprintf (fp_drvdb, "%s", buf); if ( buf [strlen (buf) - 1] != '\n' ) @@ -2331,7 +2334,7 @@ i = 0; done = !(i < npldynamicdevices); while( !done ) { - char *p = fgets( buf, 300, fp_drvdb ); + char *p = fgets( buf, BUFFER2_SIZE, fp_drvdb ); if (p == 0) { done = 1; @@ -2510,7 +2513,7 @@ { #ifdef ENABLE_DYNDRIVERS int i, drvidx; - char sym[60]; + char sym[BUFFER_SIZE]; char *tag; int n=plsc->device - 1; @@ -2552,11 +2555,11 @@ /* Load the driver if it hasn't been loaded yet. */ if (!driver->dlhand) { - char drvspec[ 400 ]; + char drvspec[ DRVSPEC_SIZE ]; #ifdef LTDL_WIN32 - snprintf( drvspec, 400, "%s", driver->drvnam ); + snprintf( drvspec, DRVSPEC_SIZE, "%s", driver->drvnam ); #else - snprintf( drvspec, 400, "%s/%s", plGetDrvDir (), driver->drvnam ); + snprintf( drvspec, DRVSPEC_SIZE, "%s/%s", plGetDrvDir (), driver->drvnam ); #endif /* LTDL_WIN32 */ pldebug("plLoadDriver", "Trying to load %s on %s\n", @@ -2577,7 +2580,7 @@ /* Now we are ready to ask the driver's device dispatch init function to initialize the entries in the dispatch table. */ - snprintf( sym, 60, "plD_dispatch_init_%s", tag ); + snprintf( sym, BUFFER_SIZE, "plD_dispatch_init_%s", tag ); { PLDispatchInit dispatch_init = (PLDispatchInit) lt_dlsym( driver->dlhand, sym ); if (!dispatch_init) Modified: trunk/src/plctrl.c =================================================================== --- trunk/src/plctrl.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/src/plctrl.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -53,6 +53,8 @@ /* Random number generator (Mersenne Twister) */ #include "mt19937ar.h" +#define BUFFER_SIZE 256 + /* Static functions */ /* Used by any external init code to suggest a path */ @@ -120,8 +122,8 @@ return; } if (icol0 < 0 || icol0 >= plsc->ncol0) { - char buffer[256]; - snprintf(buffer, 256, "plcol0: Invalid color map entry: %d", (int) icol0); + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plcol0: Invalid color map entry: %d", (int) icol0); plabort(buffer); return; } @@ -152,8 +154,8 @@ return; } if (col1 < 0 || col1 > 1) { - char buffer[256]; - snprintf(buffer, 256, "plcol1: Invalid color map position: %f", (PLFLT) col1); + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plcol1: Invalid color map position: %f", (PLFLT) col1); plabort(buffer); return; } @@ -232,14 +234,14 @@ if (plsc->cmap0 == NULL) plscmap0n(0); if (icol0 < 0 || icol0 >= plsc->ncol0) { - char buffer[256]; - snprintf(buffer, 256, "plscol0: Illegal color table value: %d", (int) icol0); + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plscol0: Illegal color table value: %d", (int) icol0); plabort(buffer); return; } if ((r < 0 || r > 255) || (g < 0 || g > 255) || (b < 0 || b > 255)) { - char buffer[256]; - snprintf(buffer, 256, "plscol0: Invalid RGB color: %d, %d, %d", + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plscol0: Invalid RGB color: %d, %d, %d", (int) r, (int) g, (int) b); plabort(buffer); return; @@ -261,14 +263,14 @@ if (plsc->cmap0 == NULL) plscmap0n(0); if (icol0 < 0 || icol0 >= plsc->ncol0) { - char buffer[256]; - snprintf(buffer, 256, "plscol0a: Illegal color table value: %d", (int) icol0); + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plscol0a: Illegal color table value: %d", (int) icol0); plabort(buffer); return; } if ((r < 0 || r > 255) || (g < 0 || g > 255) || (b < 0 || b > 255) || (a < 0 || a > 1.0)) { - char buffer[256]; - snprintf(buffer, 256, "plscol0a: Invalid RGB color: %d, %d, %d, %f", + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plscol0a: Invalid RGB color: %d, %d, %d, %f", (int) r, (int) g, (int) b, (double) a); plabort(buffer); return; @@ -301,8 +303,8 @@ *b = -1; if (icol0 < 0 || icol0 > plsc->ncol0) { - char buffer[256]; - snprintf(buffer, 256, "plgcol0: Invalid color index: %d", (int) icol0); + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plgcol0: Invalid color index: %d", (int) icol0); plabort(buffer); return; } @@ -333,8 +335,8 @@ *a = -1.0; if (icol0 < 0 || icol0 > plsc->ncol0) { - char buffer[256]; - snprintf(buffer, 256, "plgcol0: Invalid color index: %d", (int) icol0); + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plgcol0: Invalid color index: %d", (int) icol0); plabort(buffer); return; } @@ -366,8 +368,8 @@ (g[i] < 0 || g[i] > 255) || (b[i] < 0 || b[i] > 255)) { - char buffer[256]; - snprintf(buffer, 256, "plscmap0: Invalid RGB color: %d, %d, %d", + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plscmap0: Invalid RGB color: %d, %d, %d", (int) r[i], (int) g[i], (int) b[i]); plabort(buffer); return; @@ -403,8 +405,8 @@ (b[i] < 0 || b[i] > 255) || (a[i] < 0.0 || a[i] > 1.0)) { - char buffer[256]; - snprintf(buffer, 256, "plscmap0a: Invalid RGB color: %d, %d, %d, %f", + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plscmap0a: Invalid RGB color: %d, %d, %d, %f", (int) r[i], (int) g[i], (int) b[i], (double) a[i]); plabort(buffer); return; @@ -439,8 +441,8 @@ (g[i] < 0 || g[i] > 255) || (b[i] < 0 || b[i] > 255)) { - char buffer[256]; - snprintf(buffer, 256, "plscmap1: Invalid RGB color: %d, %d, %d", + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plscmap1: Invalid RGB color: %d, %d, %d", (int) r[i], (int) g[i], (int) b[i]); plabort(buffer); return; @@ -475,8 +477,8 @@ (b[i] < 0 || b[i] > 255) || (a[i] < 0.0 || a[i] > 1.0)) { - char buffer[256]; - snprintf(buffer, 256, "plscmap1a: Invalid RGB color: %d, %d, %d, %f", + char buffer[BUFFER_SIZE]; + snprintf(buffer, BUFFER_SIZE, "plscmap1a: Invalid RGB color: %d, %d, %d, %f", (int) r[i], (int) g[i], (int) b[i], (double) a[i]); plabort(buffer); return; @@ -1778,7 +1780,7 @@ { int i = 0, count = 0; size_t len; - char line[256]; + char line[BUFFER_SIZE]; while (pls->OutFile == NULL) { @@ -1835,10 +1837,10 @@ void plP_getmember(PLStream *pls) { - char tmp[256]; - char prefix[256]; + char tmp[BUFFER_SIZE]; + char prefix[BUFFER_SIZE]; char* suffix; - char num[256]; + char num[BUFFER_SIZE]; int maxlen; maxlen = strlen(pls->BaseName) + 10; @@ -1852,13 +1854,13 @@ suffix = strstr (pls->BaseName, "%n"); - snprintf(tmp, 256, "%%0%1ii", (int) pls->fflen); - snprintf(num, 256, tmp, pls->member); + snprintf(tmp, BUFFER_SIZE, "%%0%1ii", (int) pls->fflen); + snprintf(num, BUFFER_SIZE, tmp, pls->member); if (suffix == NULL) snprintf (pls->FileName, maxlen, "%s.%s", pls->BaseName, num); else { - strncpy (prefix, pls->BaseName, 256); + strncpy (prefix, pls->BaseName, BUFFER_SIZE); prefix [suffix - pls->BaseName] = 0; snprintf (pls->FileName, maxlen, "%s%s%s", prefix, num, suffix + 2); } @@ -1875,7 +1877,7 @@ void plP_sfnam(PLStream *pls, const char *fnam) { - char prefix[256]; + char prefix[BUFFER_SIZE]; char* suffix; int maxlen; pls->OutFile = NULL; @@ -1894,7 +1896,7 @@ if (suffix == NULL) strncpy(pls->FileName, fnam, maxlen); else { - strncpy (prefix, fnam, 256); + strncpy (prefix, fnam, BUFFER_SIZE); prefix [suffix - fnam] = 0; snprintf (pls->FileName, maxlen, "%s%s", prefix, suffix + 2); } @@ -2057,7 +2059,7 @@ { int m; int i = 0; - char line[256]; + char line[BUFFER_SIZE]; while (i++ < 10) { fputs(s, stdout); @@ -2088,7 +2090,7 @@ PLFLT m; double m1; int i = 0; - char line[256]; + char line[BUFFER_SIZE]; while (i++ < 10) { fputs(s, stdout); Modified: trunk/src/plfreetype.c =================================================================== --- trunk/src/plfreetype.c 2009-02-08 21:15:41 UTC (rev 9474) +++ trunk/src/plfreetype.c 2009-02-08 22:05:56 UTC (rev 9475) @@ -558,7 +558,7 @@ FT_Data *FT; char *a; /* font paths and file names can be long so leave generous (1024) room */ - char font_dir[1024]; + char font_dir[PLPLOT_MAX_PATH]; /* N.B. must be in exactly same order as TrueTypeLookup */ const char *env_font_names[N_TrueTypeLookup] = { "PLPLOT_FREETYPE_SANS_FONT", @@ -672,9 +672,9 @@ */ if ((a = getenv("PLPLOT_FREETYPE_FONT_DIR")) != NULL) - strncpy(font_dir,a,1024); + strncpy(font_dir,a,PLPLOT_MAX_PATH); else - strncpy(font_dir,default_unix_font_dir,1024); + strncpy(font_dir,default_unix_font_dir,PLPLOT_MAX_PATH); #endif @@ -701,16 +701,16 @@ #else if ((a[0]=='/')||(a[0]=='~')) /* check for unix abs path */ #endif - strncpy(FT->font_name[i],a,1024); + strncpy(FT->font_name[i],a,PLPLOT_MAX_PATH); else { - strncpy(FT->font_name[i],font_dir,1024); - strncat(FT->font_name[i],a,1024); + strncpy(FT->font_name[i],font_dir,PLPLOT_MAX_PATH); + strncat(FT->font_name[i],a,PLPLOT_MAX_PATH); } } else { - strncpy(FT->font_name[i],font_dir,1024); - strncat(FT->font_name[i],(char *)TrueTypeLookup[i].pfont,1024); + strncpy(FT->font_name[i],font_dir,PLPLOT_MAX_PATH); + strncat(FT->font_name[i],(char *)TrueTypeLookup[i].pfont,PLPLOT_MAX_PATH); } { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |