diff options
author | Simon Howard | 2014-04-01 20:43:45 -0400 |
---|---|---|
committer | Simon Howard | 2014-04-01 20:43:45 -0400 |
commit | 8eb3200286d523379295143ce3f44d77ce036d4b (patch) | |
tree | ac0edb56027f285425d896e12a1b14d78ad294b9 /src/i_oplmusic.c | |
parent | 565a1f08566520147a5abff5744dbcc256e5030c (diff) | |
download | chocolate-doom-8eb3200286d523379295143ce3f44d77ce036d4b.tar.gz chocolate-doom-8eb3200286d523379295143ce3f44d77ce036d4b.tar.bz2 chocolate-doom-8eb3200286d523379295143ce3f44d77ce036d4b.zip |
Replace all snprintf() calls with M_snprintf().
The Windows API has an _snprintf function that is not the same as
Unix's snprintf(): if the string is truncated then no trailing NUL
character is appended. This makes the function unsafe. Define a
replacement/wrapper called M_snprintf that works the same but always
appends a trailing NUL, for safety on Windows and other OSes that
behave like this.
Do the same thing for vsnprintf(), and update HACKING to list
snprintf/vsnprintf as forbidden functions. This fixes #375;
thanks to Quasar for pointing out the different behavior of these
functions.
Diffstat (limited to 'src/i_oplmusic.c')
-rw-r--r-- | src/i_oplmusic.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c index 379537dd..142e401a 100644 --- a/src/i_oplmusic.c +++ b/src/i_oplmusic.c @@ -1527,11 +1527,11 @@ void I_OPL_DevMessages(char *result, size_t result_len) if (num_tracks == 0) { - snprintf(result, result_len, "No OPL track!"); + M_snprintf(result, result_len, "No OPL track!"); return; } - snprintf(result, result_len, "Tracks:\n"); + M_snprintf(result, result_len, "Tracks:\n"); lines = 1; for (i = 0; i < NumActiveChannels(); ++i) @@ -1543,18 +1543,18 @@ void I_OPL_DevMessages(char *result, size_t result_len) instr_num = tracks[0].channels[i].instrument - main_instrs; - snprintf(tmp, sizeof(tmp), - "chan %i: %c i#%i (%s)\n", - i, - ChannelInUse(&tracks[0].channels[i]) ? '\'' : ' ', - instr_num + 1, - main_instr_names[instr_num]); + M_snprintf(tmp, sizeof(tmp), + "chan %i: %c i#%i (%s)\n", + i, + ChannelInUse(&tracks[0].channels[i]) ? '\'' : ' ', + instr_num + 1, + main_instr_names[instr_num]); M_StringConcat(result, tmp, result_len); ++lines; } - snprintf(tmp, sizeof(tmp), "\nLast percussion:\n"); + M_snprintf(tmp, sizeof(tmp), "\nLast percussion:\n"); M_StringConcat(result, tmp, result_len); lines += 2; @@ -1566,11 +1566,11 @@ void I_OPL_DevMessages(char *result, size_t result_len) break; } - snprintf(tmp, sizeof(tmp), - "%cp#%i (%s)\n", - i == 0 ? '\'' : ' ', - last_perc[i], - percussion_names[last_perc[i] - 35]); + M_snprintf(tmp, sizeof(tmp), + "%cp#%i (%s)\n", + i == 0 ? '\'' : ' ', + last_perc[i], + percussion_names[last_perc[i] - 35]); M_StringConcat(result, tmp, result_len); ++lines; |