diff options
author | Simon Howard | 2014-04-01 20:56:33 -0400 |
---|---|---|
committer | Simon Howard | 2014-04-01 20:56:33 -0400 |
commit | 17c14e1fad6dc277a6e58e4f421d5c65e210d1fe (patch) | |
tree | fab7248ca23ce615c62222377a3ff5cab6bbeb73 | |
parent | 8eb3200286d523379295143ce3f44d77ce036d4b (diff) | |
download | chocolate-doom-17c14e1fad6dc277a6e58e4f421d5c65e210d1fe.tar.gz chocolate-doom-17c14e1fad6dc277a6e58e4f421d5c65e210d1fe.tar.bz2 chocolate-doom-17c14e1fad6dc277a6e58e4f421d5c65e210d1fe.zip |
setup: Eliminate use of sprintf().
Use M_snprintf() or M_StringJoin() instead where appropriate.
This fixes #371.
-rw-r--r-- | src/setup/display.c | 6 | ||||
-rw-r--r-- | src/setup/execute.c | 9 | ||||
-rw-r--r-- | src/setup/keyboard.c | 3 | ||||
-rw-r--r-- | src/setup/mode.c | 7 | ||||
-rw-r--r-- | src/setup/multiplayer.c | 14 | ||||
-rw-r--r-- | src/setup/txt_joybinput.c | 7 |
6 files changed, 21 insertions, 25 deletions
diff --git a/src/setup/display.c b/src/setup/display.c index 1c0f8ef4..da440fce 100644 --- a/src/setup/display.c +++ b/src/setup/display.c @@ -29,6 +29,7 @@ #include "textscreen.h" #include "m_config.h" +#include "m_misc.h" #include "mode.h" #include "display.h" @@ -152,8 +153,7 @@ void SetDisplayDriver(void) { char *env_string; - env_string = malloc(strlen(video_driver) + 30); - sprintf(env_string, "SDL_VIDEODRIVER=%s", video_driver); + env_string = M_StringJoin("SDL_VIDEODRIVER=", video_driver, NULL); putenv(env_string); free(env_string); } @@ -487,7 +487,7 @@ static void GenerateModesTable(TXT_UNCAST_ARG(widget), continue; } - sprintf(buf, "%ix%i", modes[i].w, modes[i].h); + M_snprintf(buf, sizeof(buf), "%ix%i", modes[i].w, modes[i].h); rbutton = TXT_NewRadioButton(buf, &vidmode, i); TXT_AddWidget(modes_table, rbutton); TXT_SignalConnect(rbutton, "selected", ModeSelected, &modes[i]); diff --git a/src/setup/execute.c b/src/setup/execute.c index 076b39fd..9d798264 100644 --- a/src/setup/execute.c +++ b/src/setup/execute.c @@ -61,7 +61,6 @@ struct execute_context_s static char *TempFile(char *s) { - char *result; char *tempdir; #ifdef _WIN32 @@ -79,10 +78,7 @@ static char *TempFile(char *s) tempdir = "/tmp"; #endif - result = malloc(strlen(tempdir) + strlen(s) + 2); - sprintf(result, "%s%c%s", tempdir, DIR_SEPARATOR, s); - - return result; + return M_StringJoin(tempdir, DIR_SEPARATOR_S, s, NULL); } static int ArgumentNeedsEscape(char *arg) @@ -345,8 +341,7 @@ int ExecuteDoom(execute_context_t *context) // Build the command line - response_file_arg = malloc(strlen(context->response_file) + 2); - sprintf(response_file_arg, "@%s", context->response_file); + response_file_arg = M_StringJoin("@", context->response_file); // Run Doom diff --git a/src/setup/keyboard.c b/src/setup/keyboard.c index 930d2714..76880f49 100644 --- a/src/setup/keyboard.c +++ b/src/setup/keyboard.c @@ -23,6 +23,7 @@ #include "doomtype.h" #include "m_config.h" #include "m_controls.h" +#include "m_misc.h" #include "execute.h" #include "txt_keyinput.h" @@ -171,7 +172,7 @@ static void AddSectionLabel(txt_table_t *table, char *title, boolean add_space) NULL); } - sprintf(buf, " - %s - ", title); + M_snprintf(buf, sizeof(buf), " - %s - ", title); TXT_AddWidgets(table, TXT_NewLabel(buf), TXT_NewStrut(0, 0), NULL); diff --git a/src/setup/mode.c b/src/setup/mode.c index f5387750..1ad68bd1 100644 --- a/src/setup/mode.c +++ b/src/setup/mode.c @@ -34,6 +34,7 @@ #include "m_argv.h" #include "m_config.h" #include "m_controls.h" +#include "m_misc.h" #include "compatibility.h" #include "display.h" @@ -140,8 +141,7 @@ static void BindMiscVariables(void) if (!strcmp(savedir, "")) { free(savedir); - savedir = malloc(10); - sprintf(savedir, "hexndata%c", DIR_SEPARATOR); + savedir = "hexndata" DIR_SEPARATOR_S; } } @@ -215,8 +215,7 @@ static void SetExecutable(mission_config_t *config) extension = ""; #endif - executable = malloc(strlen(config->executable) + 5); - sprintf(executable, "%s%s", config->executable, extension); + executable = M_StringJoin(config->executable, extension, NULL); } static void SetMission(mission_config_t *config) diff --git a/src/setup/multiplayer.c b/src/setup/multiplayer.c index d9fa3f4e..b151a10d 100644 --- a/src/setup/multiplayer.c +++ b/src/setup/multiplayer.c @@ -308,11 +308,11 @@ static void UpdateWarpButton(void) if (warptype == WARP_ExMy) { - sprintf(buf, "E%iM%i", warpepisode, warpmap); + M_snprintf(buf, sizeof(buf), "E%iM%i", warpepisode, warpmap); } else if (warptype == WARP_MAPxy) { - sprintf(buf, "MAP%02i", warpmap); + M_snprintf(buf, sizeof(buf), "MAP%02i", warpmap); } TXT_SetButtonLabel(warpbutton, buf); @@ -425,7 +425,7 @@ static void LevelSelectDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(user_data)) continue; } - sprintf(buf, " E%iM%i ", x, y); + M_snprintf(buf, sizeof(buf), " E%iM%i ", x, y); button = TXT_NewButton(buf); TXT_SignalConnect(button, "pressed", SetExMyWarp, (void *) (x * 10 + y)); @@ -457,7 +457,7 @@ static void LevelSelectDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(user_data)) continue; } - sprintf(buf, " MAP%02i ", l); + M_snprintf(buf, sizeof(buf), " MAP%02i ", l); button = TXT_NewButton(buf); TXT_SignalConnect(button, "pressed", SetMAPxyWarp, (void *) l); @@ -898,7 +898,7 @@ static void QueryResponseCallback(net_addr_t *addr, char ping_time_str[16]; char description[47]; - sprintf(ping_time_str, "%ims", ping_time); + M_snprintf(ping_time_str, sizeof(ping_time_str), "%ims", ping_time); M_StringCopy(description, querydata->description, sizeof(description)); @@ -1094,7 +1094,7 @@ void MultiplayerConfig(void) for (i=0; i<10; ++i) { - sprintf(buf, "#%i ", i + 1); + M_snprintf(buf, sizeof(buf), "#%i ", i + 1); label = TXT_NewLabel(buf); TXT_SetFGColor(label, TXT_COLOR_BRIGHT_CYAN); @@ -1119,7 +1119,7 @@ void BindMultiplayerVariables(void) for (i=0; i<10; ++i) { - sprintf(buf, "chatmacro%i", i); + M_snprintf(buf, sizeof(buf), "chatmacro%i", i); M_BindVariable(buf, &chat_macros[i]); } diff --git a/src/setup/txt_joybinput.c b/src/setup/txt_joybinput.c index ce466d50..4e41f3fd 100644 --- a/src/setup/txt_joybinput.c +++ b/src/setup/txt_joybinput.c @@ -125,9 +125,9 @@ static void TXT_JoystickInputSizeCalc(TXT_UNCAST_ARG(joystick_input)) joystick_input->widget.h = 1; } -static void GetJoystickButtonDescription(int button, char *buf) +static void GetJoystickButtonDescription(int button, char *buf, size_t buf_len) { - sprintf(buf, "BUTTON #%i", button + 1); + M_snprintf(buf, buf_len, "BUTTON #%i", button + 1); } static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input)) @@ -142,7 +142,8 @@ static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input)) } else { - GetJoystickButtonDescription(*joystick_input->variable, buf); + GetJoystickButtonDescription(*joystick_input->variable, + buf, sizeof(buf)); } TXT_SetWidgetBG(joystick_input); |