diff options
author | Chris Liddell <chris.liddell@artifex.com> | 2022-02-16 12:18:16 +0000 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2022-02-16 14:35:09 +0000 |
commit | 61714df72f24c852a3a23d96fef0392d3fe9ade2 (patch) | |
tree | acd3f9f3e1aa7bbf1df6b240bd6f1bab21fae72e /psi | |
parent | c39ce3b77d8b9e35e02490ac646001f830b7cae5 (diff) | |
download | ghostpdl-61714df72f24c852a3a23d96fef0392d3fe9ade2.tar.gz |
Move psi/ files from gs_sprintf to gs_snprintf
Diffstat (limited to 'psi')
-rw-r--r-- | psi/dmmain.c | 6 | ||||
-rw-r--r-- | psi/dpmain.c | 52 | ||||
-rw-r--r-- | psi/iparam.c | 4 | ||||
-rw-r--r-- | psi/iutil.c | 27 | ||||
-rw-r--r-- | psi/zdouble.c | 10 | ||||
-rw-r--r-- | psi/zfont2.c | 4 |
6 files changed, 52 insertions, 51 deletions
diff --git a/psi/dmmain.c b/psi/dmmain.c index 1af0d787e..7fee91572 100644 --- a/psi/dmmain.c +++ b/psi/dmmain.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2021 Artifex Software, Inc. +/* Copyright (C) 2001-2022 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -640,8 +640,8 @@ void main(void) argv[1] = ddevice; argv[2] = dformat; - gs_sprintf(ddevice, "-sDEVICE=display"); - gs_sprintf(dformat, "-dDisplayFormat=%d", display_format); + gs_snprintf(ddevice, sizeof(ddevice), "-sDEVICE=display"); + gs_snprintf(dformat, sizeof(dformat), "-dDisplayFormat=%d", display_format); /* Run Ghostscript */ if (gsapi_new_instance(&instance, NULL) < 0) diff --git a/psi/dpmain.c b/psi/dpmain.c index e862f3785..50d394860 100644 --- a/psi/dpmain.c +++ b/psi/dpmain.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2021 Artifex Software, Inc. +/* Copyright (C) 2001-2022 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -116,9 +116,9 @@ gs_free_dll(void) return TRUE; rc = DosFreeModule(gsdll.hmodule); if (rc) { - gs_sprintf(buf, "DosFreeModule returns %d\n", rc); + gs_snprintf(buf, sizeof(buf), "DosFreeModule returns %d\n", rc); gs_addmess(buf); - gs_sprintf(buf, "Unloaded GSDLL\n\n"); + gs_snprintf(buf, sizeof(buf), "Unloaded GSDLL\n\n"); gs_addmess(buf); } return !rc; @@ -166,7 +166,7 @@ gs_load_dll(void) dllname = szDllName; #ifdef DEBUG if (debug) { - gs_sprintf(buf, "Trying to load %s\n", dllname); + gs_snprintf(buf, sizeof(buf), "Trying to load %s\n", dllname); gs_addmess(buf); } #endif @@ -188,7 +188,7 @@ gs_load_dll(void) dllname = fullname; #ifdef DEBUG if (debug) { - gs_sprintf(buf, "Trying to load %s\n", dllname); + gs_snprintf(buf, sizeof(buf), "Trying to load %s\n", dllname); gs_addmess(buf); } #endif @@ -199,7 +199,7 @@ gs_load_dll(void) dllname = shortname; #ifdef DEBUG if (debug) { - gs_sprintf(buf, "Trying to load %s\n", dllname); + gs_snprintf(buf, sizeof(buf), "Trying to load %s\n", dllname); gs_addmess(buf); } #endif @@ -213,21 +213,21 @@ gs_load_dll(void) #endif if ((rc = DosQueryProcAddr(gsdll.hmodule, 0, "GSAPI_REVISION", (PFN *) (&gsdll.revision))) != 0) { - gs_sprintf(buf, "Can't find GSAPI_REVISION, rc = %d\n", rc); + gs_snprintf(buf, sizeof(buf), "Can't find GSAPI_REVISION, rc = %d\n", rc); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; } /* check DLL version */ if (gsdll.revision(&rv, sizeof(rv)) != 0) { - gs_sprintf(buf, "Unable to identify Ghostscript DLL revision - it must be newer than needed.\n"); + gs_snprintf(buf, sizeof(buf), "Unable to identify Ghostscript DLL revision - it must be newer than needed.\n"); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; } if (rv.revision != GS_REVISION) { - gs_sprintf(buf, "Wrong version of DLL found.\n Found version %ld\n Need version %ld\n", rv.revision, (long)GS_REVISION); + gs_snprintf(buf, sizeof(buf), "Wrong version of DLL found.\n Found version %ld\n Need version %ld\n", rv.revision, (long)GS_REVISION); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; @@ -235,35 +235,35 @@ gs_load_dll(void) if ((rc = DosQueryProcAddr(gsdll.hmodule, 0, "GSAPI_NEW_INSTANCE", (PFN *) (&gsdll.new_instance))) != 0) { - gs_sprintf(buf, "Can't find GSAPI_NEW_INSTANCE, rc = %d\n", rc); + gs_snprintf(buf, sizeof(buf), "Can't find GSAPI_NEW_INSTANCE, rc = %d\n", rc); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; } if ((rc = DosQueryProcAddr(gsdll.hmodule, 0, "GSAPI_DELETE_INSTANCE", (PFN *) (&gsdll.delete_instance))) != 0) { - gs_sprintf(buf, "Can't find GSAPI_DELETE_INSTANCE, rc = %d\n", rc); + gs_snprintf(buf, sizeof(buf), "Can't find GSAPI_DELETE_INSTANCE, rc = %d\n", rc); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; } if ((rc = DosQueryProcAddr(gsdll.hmodule, 0, "GSAPI_SET_STDIO", (PFN *) (&gsdll.set_stdio))) != 0) { - gs_sprintf(buf, "Can't find GSAPI_SET_STDIO, rc = %d\n", rc); + gs_snprintf(buf, sizeof(buf), "Can't find GSAPI_SET_STDIO, rc = %d\n", rc); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; } if ((rc = DosQueryProcAddr(gsdll.hmodule, 0, "GSAPI_SET_DISPLAY_CALLBACK", (PFN *) (&gsdll.set_display_callback))) != 0) { - gs_sprintf(buf, "Can't find GSAPI_SET_DISPLAY_CALLBACK, rc = %d\n", rc); + gs_snprintf(buf, sizeof(buf), "Can't find GSAPI_SET_DISPLAY_CALLBACK, rc = %d\n", rc); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; } if ((rc = DosQueryProcAddr(gsdll.hmodule, 0, "GSAPI_SET_POLL", (PFN *) (&gsdll.set_poll))) != 0) { - gs_sprintf(buf, "Can't find GSAPI_SET_POLL, rc = %d\n", rc); + gs_snprintf(buf, sizeof(buf), "Can't find GSAPI_SET_POLL, rc = %d\n", rc); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; @@ -271,27 +271,27 @@ gs_load_dll(void) if ((rc = DosQueryProcAddr(gsdll.hmodule, 0, "GSAPI_INIT_WITH_ARGS", (PFN *) (&gsdll.init_with_args))) != 0) { - gs_sprintf(buf, "Can't find GSAPI_INIT_WITH_ARGS, rc = %d\n", rc); + gs_snprintf(buf, sizeof(buf), "Can't find GSAPI_INIT_WITH_ARGS, rc = %d\n", rc); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; } if ((rc = DosQueryProcAddr(gsdll.hmodule, 0, "GSAPI_RUN_STRING", (PFN *) (&gsdll.run_string))) != 0) { - gs_sprintf(buf, "Can't find GSAPI_RUN_STRING, rc = %d\n", rc); + gs_snprintf(buf, sizeof(buf), "Can't find GSAPI_RUN_STRING, rc = %d\n", rc); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; } if ((rc = DosQueryProcAddr(gsdll.hmodule, 0, "GSAPI_EXIT", (PFN *) (&gsdll.exit))) != 0) { - gs_sprintf(buf, "Can't find GSAPI_EXIT, rc = %d\n", rc); + gs_snprintf(buf, sizeof(buf), "Can't find GSAPI_EXIT, rc = %d\n", rc); gs_addmess(buf); gs_load_dll_cleanup(); return FALSE; } } else { - gs_sprintf(buf, "Can't load Ghostscript DLL %s \nDosLoadModule rc = %d\n", + gs_snprintf(buf, sizeof(buf), "Can't load Ghostscript DLL %s \nDosLoadModule rc = %d\n", szDllName, rc); gs_addmess(buf); gs_load_dll_cleanup(); @@ -389,10 +389,10 @@ static int run_gspmdrv(IMAGE *img) if (debug) fprintf(stdout, "run_gspmdrv: starting\n"); #endif - gs_sprintf(id, ID_NAME, img->pid, (ULONG)img->device); + gs_snprintf(id, sizeof(id), ID_NAME, img->pid, (ULONG)img->device); /* Create termination queue - used to find out when gspmdrv terminates */ - gs_sprintf(term_queue_name, "\\QUEUES\\TERMQ_%s", id); + gs_snprintf(term_queue_name, sizeof(term_queue_name), "\\QUEUES\\TERMQ_%s", id); if (DosCreateQueue(&(img->term_queue), QUE_FIFO, term_queue_name)) { fprintf(stdout, "run_gspmdrv: failed to create termination queue\n"); return gs_error_limitcheck; @@ -420,7 +420,7 @@ static int run_gspmdrv(IMAGE *img) /* arguments are: */ /* (1) -d (display) option */ /* (2) id string */ - gs_sprintf(arg, "-d %s", id); + gs_snprintf(arg, sizeof(arg), "-d %s", id); /* because gspmdrv.exe is a different EXE type to gs.exe, * we must use start session not DosExecPgm() */ @@ -608,17 +608,17 @@ int display_open(void *handle, void *device) return gs_error_limitcheck; } img->pid = pppib->pib_ulppid; /* use parent (CMD.EXE) pid */ - gs_sprintf(id, ID_NAME, img->pid, (ULONG) img->device); + gs_snprintf(id, sizeof(id), ID_NAME, img->pid, (ULONG) img->device); /* Create update event semaphore */ - gs_sprintf(name, SYNC_NAME, id); + gs_snprintf(name, sizeof(name), SYNC_NAME, id); if (DosCreateEventSem(name, &(img->sync_event), 0, FALSE)) { fprintf(stdout, "display_open: failed to create event semaphore %s\n", name); return gs_error_limitcheck; } /* Create mutex - used for preventing gspmdrv from accessing */ /* bitmap while we are changing the bitmap size. Initially unowned. */ - gs_sprintf(name, MUTEX_NAME, id); + gs_snprintf(name, sizeof(name), MUTEX_NAME, id); if (DosCreateMutexSem(name, &(img->bmp_mutex), 0, FALSE)) { DosCloseEventSem(img->sync_event); fprintf(stdout, "display_open: failed to create mutex semaphore %s\n", name); @@ -628,7 +628,7 @@ int display_open(void *handle, void *device) /* Shared memory is common to all processes so we don't want to * allocate too much. */ - gs_sprintf(name, SHARED_NAME, id); + gs_snprintf(name, sizeof(name), SHARED_NAME, id); if (DosAllocSharedMem((PPVOID) & img->bitmap, name, 13 * 1024 * 1024, PAG_READ | PAG_WRITE)) { fprintf(stdout, "display_open: failed allocating shared BMP memory %s\n", name); @@ -1036,7 +1036,7 @@ main(int argc, char *argv[]) else if (depth >= 4) format = DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | DISPLAY_DEPTH_4 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST; - gs_sprintf(dformat, "-dDisplayFormat=%d", format); + gs_snprintf(dformat, sizeof(dformat), "-dDisplayFormat=%d", format); } nargc = argc + 1; diff --git a/psi/iparam.c b/psi/iparam.c index 7fe1cb0d0..c35b516e2 100644 --- a/psi/iparam.c +++ b/psi/iparam.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2021 Artifex Software, Inc. +/* Copyright (C) 2001-2022 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -65,7 +65,7 @@ ref_to_key(const ref * pref, gs_param_key_t * key, iparam_list *plist) int len; byte *buf; - gs_sprintf(istr, "%"PRIpsint, pref->value.intval); + gs_snprintf(istr, sizeof(istr), "%"PRIpsint, pref->value.intval); len = strlen(istr); /* GC will take care of freeing this: */ buf = gs_alloc_string(plist->memory, len, "ref_to_key"); diff --git a/psi/iutil.c b/psi/iutil.c index ea582e6e2..abaa4a341 100644 --- a/psi/iutil.c +++ b/psi/iutil.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2021 Artifex Software, Inc. +/* Copyright (C) 2001-2022 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -304,7 +304,7 @@ obj_string_data(const gs_memory_t *mem, const ref *op, const byte **pchars, uint * repeatedly to print on a stream, which may require suspending at any * point to handle stream callouts. */ -static void ensure_dot(char *); +static void ensure_dot(char *, size_t); int obj_cvp(const ref * op, byte * str, uint len, uint * prlen, int full_print, uint start_pos, const gs_memory_t *mem, bool restart) @@ -340,15 +340,15 @@ obj_cvp(const ref * op, byte * str, uint len, uint * prlen, */ float value = op->value.realval; float scanned; - code = gs_sprintf(buf, "%g", value); + code = gs_snprintf(buf, sizeof(buf), "%g", value); if (code <= 0) return_error(gs_error_undefinedresult); code = sscanf(buf, "%f", &scanned); if (code <= 0) return_error(gs_error_undefinedresult); if (scanned != value) - gs_sprintf(buf, "%.9g", value); - ensure_dot(buf); + gs_snprintf(buf, sizeof(buf), "%.9g", value); + ensure_dot(buf, 256); goto rs; } case t_operator: @@ -502,7 +502,7 @@ other: data = (const byte *)(op->value.boolval ? "true" : "false"); break; case t_integer: - gs_sprintf(buf, "%"PRIpsint, op->value.intval); + gs_snprintf(buf, sizeof(buf), "%"PRIpsint, op->value.intval); break; case t_string: check_read(*op); @@ -537,7 +537,7 @@ other: break; } /* Internal operator, no name. */ - gs_sprintf(buf, "@"PRI_INTPTR, (intptr_t) op->value.opproc); + gs_snprintf(buf, sizeof(buf), "@"PRI_INTPTR, (intptr_t) op->value.opproc); break; } case t_real: @@ -548,11 +548,11 @@ other: * library implementation. Work around this here. */ if (op->value.realval == (float)0.0001) { - strcpy(buf, "0.0001"); + strncpy(buf, "0.0001", 256); } else { - gs_sprintf(buf, "%g", op->value.realval); + gs_snprintf(buf, sizeof(buf), "%g", op->value.realval); } - ensure_dot(buf); + ensure_dot(buf, 256); break; default: data = (const byte *)"--nostringval--"; @@ -573,17 +573,18 @@ nl: if (size < start_pos) * Re-format the exponent to satisfy Genoa CET test. */ static void -ensure_dot(char *buf) +ensure_dot(char *buf, size_t buflen) { char *pe = strchr(buf, 'e'); if (pe) { int i; (void)sscanf(pe + 1, "%d", &i); + buflen -= (size_t)(pe - buf) /* MSVC .net 2005 express doesn't support "%+02d" */ if (i >= 0) - gs_sprintf(pe + 1, "+%02d", i); + gs_snprintf(pe + 1, buflen, "+%02d", i); else - gs_sprintf(pe + 1, "-%02d", -i); + gs_snprintf(pe + 1, buflen, "-%02d", -i); } else if (strchr(buf, '.') == NULL) { strcat(buf, ".0"); } diff --git a/psi/zdouble.c b/psi/zdouble.c index e6e7bad6d..ae439811f 100644 --- a/psi/zdouble.c +++ b/psi/zdouble.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2021 Artifex Software, Inc. +/* Copyright (C) 2001-2022 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -323,7 +323,7 @@ zcvsd(i_ctx_t *i_ctx_p) len = r_size(op - 1); if (len > MAX_CHARS) return_error(gs_error_limitcheck); - gs_sprintf(buf, "%f", 1.5); + gs_snprintf(buf, sizeof(buf), "%f", 1.5); dot = buf[1]; /* locale-dependent */ memcpy(str, op[-1].value.bytes, len); /* @@ -406,7 +406,7 @@ zdcvs(i_ctx_t *i_ctx_p) if (code < 0) return code; check_write_type(*op, t_string); - gs_sprintf(str, "%f", 1.5); + gs_snprintf(str, sizeof(str), "%f", 1.5); dot = str[1]; /* locale-dependent */ /* * To get fully accurate output results for IEEE double- @@ -420,10 +420,10 @@ zdcvs(i_ctx_t *i_ctx_p) { double scanned; - gs_sprintf(str, "%g", num); + gs_snprintf(str, sizeof(str), "%g", num); sscanf(str, "%lf", &scanned); if (scanned != num) - gs_sprintf(str, "%.16g", num); + gs_snprintf(str, sizeof(str), "%.16g", num); } len = strlen(str); if (len > r_size(op)) diff --git a/psi/zfont2.c b/psi/zfont2.c index ae5d29d08..2be4279a4 100644 --- a/psi/zfont2.c +++ b/psi/zfont2.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2021 Artifex Software, Inc. +/* Copyright (C) 2001-2022 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -2705,7 +2705,7 @@ parse_font(i_ctx_t *i_ctx_p, ref *topdict, return sid; if ((code = make_name_from_sid(i_ctx_p, &name, strings, data, sid)) < 0) { char buf[40]; - int len = gs_sprintf(buf, "sid-%d", sid); + int len = gs_snprintf(buf, sizeof(buf), "sid-%d", sid); if ((code = name_ref(imemory, (unsigned char *)buf, len, &name, 1)) < 0) return code; |