1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 04_sprintf.dpatch by <ds@flibble.youmustbejoking.demon.co.uk>
4
## All lines beginning with `## DP:' are a description of the patch.
8
diff -urNad glbsp-2.20~/Makefile glbsp-2.20/Makefile
9
--- glbsp-2.20~/Makefile 2006-08-13 12:53:45.000000000 +0100
10
+++ glbsp-2.20/Makefile 2006-08-13 12:53:46.178842615 +0100
15
-CFLAGS=-O2 -Wall -DGLBSP_TEXT -DUNIX -DINLINE_G=inline
16
+CFLAGS=-O2 -Wall -DGLBSP_TEXT -DUNIX -DINLINE_G=inline -D_GNU_SOURCE
19
OBJS=$(SYSDIR)/main.o \
20
diff -urNad glbsp-2.20~/glbsp.c glbsp-2.20/glbsp.c
21
--- glbsp-2.20~/glbsp.c 2006-08-13 12:53:45.000000000 +0100
22
+++ glbsp-2.20/glbsp.c 2006-08-13 12:53:46.178842615 +0100
24
const nodebuildfuncs_t *cur_funcs = NULL;
25
volatile nodebuildcomms_t *cur_comms = NULL;
27
-static char glbsp_message_buf[1024];
30
const nodebuildinfo_t default_buildinfo =
33
// The -hexen option is only kept for backwards compatibility
34
HANDLE_BOOLEAN("hexen", force_hexen)
36
- sprintf(glbsp_message_buf, "Unknown option: %s", argv[0]);
37
- SetErrorMsg(glbsp_message_buf);
38
+ SetErrorMsg("Unknown option: %s", argv[0]);
41
return GLBSP_E_BadArgs;
43
glbsp_ret_e GlbspBuildNodes(const nodebuildinfo_t *info,
44
const nodebuildfuncs_t *funcs, volatile nodebuildcomms_t *comms)
47
+ char *strbuf = NULL;
49
glbsp_ret_e ret = GLBSP_E_OK;
52
DisplayOpen(DIS_BUILDPROGRESS);
53
DisplaySetTitle("glBSP Build Progress");
55
- sprintf(strbuf, "File: %s", cur_info->input_file);
56
+ asprintf(&strbuf, "File: %s", cur_info->input_file);
58
DisplaySetBarText(2, strbuf);
59
DisplaySetBarLimit(2, CountLevels() * 10);
64
cur_comms->file_pos = 0;
66
// loop over each level in the wad
67
diff -urNad glbsp-2.20~/level.c glbsp-2.20/level.c
68
--- glbsp-2.20~/level.c 2006-08-13 12:53:45.000000000 +0100
69
+++ glbsp-2.20/level.c 2006-08-13 12:53:46.178842615 +0100
75
+ char *message = NULL;
77
const char *level_name = GetLevelName();
79
@@ -1536,13 +1536,10 @@
80
// -JL- Identify Hexen mode by presence of BEHAVIOR lump
81
lev_doing_hexen = (FindLevelLump("BEHAVIOR") != NULL);
83
- if (lev_doing_normal)
84
- sprintf(message, "Building normal and GL nodes on %s", level_name);
86
- sprintf(message, "Building GL nodes on %s", level_name);
88
- if (lev_doing_hexen)
89
- strcat(message, " (Hexen)");
90
+ asprintf (&message, "Building %sGL nodes on %s%s",
91
+ lev_doing_normal ? "normal and " : "",
93
+ lev_doing_hexen ? " (Hexen)" : "");
95
lev_doing_hexen |= cur_info->force_hexen;
98
PrintMsg("%s\n", message);
106
diff -urNad glbsp-2.20~/system.c glbsp-2.20/system.c
107
--- glbsp-2.20~/system.c 2006-08-13 12:53:45.000000000 +0100
108
+++ glbsp-2.20/system.c 2006-08-13 12:54:39.759596267 +0100
110
static int cpu_big_endian = 0;
113
-static char message_buf[1024];
116
static FILE *debug_fp = NULL;
119
void FatalError(const char *str, ...)
122
+ char *message_buf = NULL;
125
- vsprintf(message_buf, str, args);
126
+ vasprintf(&message_buf, str, args);
129
(* cur_funcs->fatal_error)("\nError: *** %s ***\n\n", message_buf);
131
+ free (message_buf);
136
void InternalError(const char *str, ...)
139
+ char *message_buf = NULL;
142
- vsprintf(message_buf, str, args);
143
+ vasprintf(&message_buf, str, args);
146
(* cur_funcs->fatal_error)("\nINTERNAL ERROR: *** %s ***\n\n", message_buf);
148
void PrintMsg(const char *str, ...)
151
+ char *message_buf = NULL;
154
- vsprintf(message_buf, str, args);
155
+ vasprintf(&message_buf, str, args);
158
(* cur_funcs->print_msg)("%s", message_buf);
160
void PrintVerbose(const char *str, ...)
163
+ char *message_buf = NULL;
165
- if (! cur_info->quiet)
166
+ if (DEBUG_ENABLED || ! cur_info->quiet)
169
- vsprintf(message_buf, str, args);
170
+ vasprintf(&message_buf, str, args);
174
+ if (! cur_info->quiet)
175
(* cur_funcs->print_msg)("%s", message_buf);
180
- va_start(args, str);
181
- vsprintf(message_buf, str, args);
184
- PrintDebug(">>> %s", message_buf);
186
+ PrintDebug(">>> %s", message_buf);
189
+ free (message_buf);
194
void PrintWarn(const char *str, ...)
197
+ char *message_buf = NULL;
200
- vsprintf(message_buf, str, args);
201
+ vasprintf(&message_buf, str, args);
204
(* cur_funcs->print_msg)("Warning: %s", message_buf);
207
PrintDebug("Warning: %s", message_buf);
210
+ free (message_buf);
214
@@ -145,35 +149,43 @@
215
void PrintMiniWarn(const char *str, ...)
218
+ char *message_buf = NULL;
220
- if (cur_info->mini_warnings)
221
+ if (DEBUG_ENABLED || cur_info->mini_warnings)
224
- vsprintf(message_buf, str, args);
225
+ vasprintf(&message_buf, str, args);
229
+ if (cur_info->mini_warnings)
230
(* cur_funcs->print_msg)("Warning: %s", message_buf);
233
cur_comms->total_small_warn++;
236
- va_start(args, str);
237
- vsprintf(message_buf, str, args);
240
PrintDebug("MiniWarn: %s", message_buf);
243
+ free (message_buf);
249
-void SetErrorMsg(const char *str)
250
+void SetErrorMsg(const char *str, ...)
252
GlbspFree(cur_comms->message);
254
- cur_comms->message = GlbspStrDup(str);
255
+ cur_comms->message = NULL;
259
+ char *message = NULL;
260
+ va_start(args, str);
261
+ vasprintf (&message, str, args);
262
+ cur_comms->message = message;
268
diff -urNad glbsp-2.20~/system.h glbsp-2.20/system.h
269
--- glbsp-2.20~/system.h 2006-08-13 12:53:45.000000000 +0100
270
+++ glbsp-2.20/system.h 2006-08-13 12:53:46.178842615 +0100
272
void PrintMiniWarn(const char *str, ...) __attribute__ ((format (printf, 1, 2)));
274
// set message for certain errors
275
-void SetErrorMsg(const char *str);
276
+void SetErrorMsg(const char *str, ...) __attribute__ ((format (printf, 1, 2)));
279
void InitEndian(void);
280
diff -urNad glbsp-2.20~/util.c glbsp-2.20/util.c
281
--- glbsp-2.20~/util.c 2006-08-13 12:53:45.000000000 +0100
282
+++ glbsp-2.20/util.c 2006-08-13 12:53:46.178842615 +0100
285
GetSystemTime(&sys_time);
287
- sprintf(str_buf, "%04d-%02d-%02d %02d:%02d:%02d.%04d",
288
+ snprintf(str_buf, sizeof(str_buf), "%04d-%02d-%02d %02d:%02d:%02d.%04d",
289
sys_time.wYear, sys_time.wMonth, sys_time.wDay,
290
sys_time.wHour, sys_time.wMinute, sys_time.wSecond,
291
sys_time.wMilliseconds * 10);
296
- sprintf(str_buf, "%04d-%02d-%02d %02d:%02d:%02d.%04d",
297
+ snprintf(str_buf, sizeof(str_buf), "%04d-%02d-%02d %02d:%02d:%02d.%04d",
298
calend_time->tm_year + 1900, calend_time->tm_mon + 1,
299
calend_time->tm_mday,
300
calend_time->tm_hour, calend_time->tm_min,
301
diff -urNad glbsp-2.20~/wad.c glbsp-2.20/wad.c
302
--- glbsp-2.20~/wad.c 2006-08-13 12:53:45.000000000 +0100
303
+++ glbsp-2.20/wad.c 2006-08-13 12:53:46.178842615 +0100
304
@@ -260,25 +260,20 @@
307
raw_wad_header_t header;
310
len = fread(&header, sizeof(header), 1, in_file);
314
- sprintf(strbuf, "Trouble reading wad header for %s [%s]",
315
+ SetErrorMsg("Trouble reading wad header for %s [%s]",
316
filename, strerror(errno));
318
- SetErrorMsg(strbuf);
322
if (! CheckMagic(header.type))
324
- sprintf(strbuf, "%s does not appear to be a wad file (bad magic)",
325
+ SetErrorMsg("%s does not appear to be a wad file (bad magic)",
328
- SetErrorMsg(strbuf);
334
if (strlen(level->name) <= 5)
336
- sprintf(name_buf, "GL_%s", level->name);
337
+ snprintf(name_buf, sizeof(name_buf), "GL_%s", level->name);
341
@@ -1014,21 +1009,15 @@
343
char *ReplaceExtension(const char *filename, const char *ext)
348
+ const char *dot_pos = strrchr (filename, '.');
350
- strcpy(buffer, filename);
352
- dot_pos = strrchr(buffer, '.');
354
+ dot_pos = filename + strlen (filename);
359
- strcat(buffer, ".");
361
- strcat(buffer, ext);
362
+ asprintf (&buffer, "%.*s.%s", (int)(dot_pos - filename), filename, ext);
364
- return UtilStrDup(buffer);
369
@@ -1270,7 +1259,7 @@
370
glbsp_ret_e ReadWadFile(const char *filename)
374
+ char *strbuf = NULL;
376
// open input wad file & read header
377
in_file = fopen(filename, "rb");
378
@@ -1278,13 +1267,11 @@
382
- sprintf(strbuf, "Cannot open WAD file: %s", filename);
383
+ SetErrorMsg("Cannot open WAD file: %s", filename);
385
- sprintf(strbuf, "Cannot open WAD file: %s [%s]", filename,
386
+ SetErrorMsg("Cannot open WAD file: %s [%s]", filename,
389
- SetErrorMsg(strbuf);
391
return GLBSP_E_ReadError;
394
@@ -1305,12 +1292,14 @@
395
DisplayOpen(DIS_FILEPROGRESS);
396
DisplaySetTitle("glBSP Reading Wad");
398
- sprintf(strbuf, "Reading: %s", filename);
399
+ asprintf(&strbuf, "Reading: %s", filename);
401
DisplaySetBarText(1, strbuf);
402
DisplaySetBarLimit(1, CountLumpTypes(LUMP_READ_ME, LUMP_READ_ME));
407
cur_comms->file_pos = 0;
410
@@ -1334,7 +1323,7 @@
411
glbsp_ret_e WriteWadFile(const char *filename)
415
+ char *strbuf = NULL;
418
PrintMsg("Saving WAD as %s\n", filename);
419
@@ -1349,11 +1338,9 @@
423
- sprintf(strbuf, "Cannot create WAD file: %s [%s]", filename,
424
+ SetErrorMsg("Cannot create WAD file: %s [%s]", filename,
427
- SetErrorMsg(strbuf);
429
return GLBSP_E_WriteError;
432
@@ -1362,12 +1349,14 @@
433
DisplayOpen(DIS_FILEPROGRESS);
434
DisplaySetTitle("glBSP Writing Wad");
436
- sprintf(strbuf, "Writing: %s", filename);
437
+ asprintf(&strbuf, "Writing: %s", filename);
439
DisplaySetBarText(1, strbuf);
440
DisplaySetBarLimit(1, CountLumpTypes(LUMP_IGNORE_ME, 0));
445
cur_comms->file_pos = 0;
447
// now write all the lumps to the output wad