Use new function flac_snprintf() where ever appropriate.

This replaces un-safe usage of sprintf() and Micorsoft's _snprintf()
with something sane.
This commit is contained in:
Erik de Castro Lopo
2013-03-17 20:56:41 +11:00
parent 06af237c70
commit 3c84f9e86b
11 changed files with 30 additions and 48 deletions

View File

@@ -24,4 +24,4 @@ noinst_PROGRAMS = test_streams
test_streams_SOURCES = \
main.c
test_streams_LDADD = -lm
test_streams_LDADD = $(top_builddir)/src/share/grabbag/libgrabbag.la -lm

View File

@@ -31,6 +31,7 @@
#endif
#include "FLAC/assert.h"
#include "FLAC/ordinals.h"
#include "share/compat.h"
#ifndef M_PI
/* math.h in VC++ doesn't seem to have this (how Microsoft is that?) */
@@ -1136,24 +1137,24 @@ int main(int argc, char *argv[])
for(samples = 0; samples < sizeof(nsamples)/sizeof(nsamples[0]); samples++) {
char fn[64];
sprintf(fn, "rt-%u-%u-%u.aiff", channels, bits_per_sample, nsamples[samples]);
flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.aiff", channels, bits_per_sample, nsamples[samples]);
if(!generate_aiff(fn, 44100, channels, bits_per_sample, nsamples[samples]))
return 1;
sprintf(fn, "rt-%u-%u-%u.wav", channels, bits_per_sample, nsamples[samples]);
flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.wav", channels, bits_per_sample, nsamples[samples]);
if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/0))
return 1;
sprintf(fn, "rt-%u-%u-%u.rf64", channels, bits_per_sample, nsamples[samples]);
flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.rf64", channels, bits_per_sample, nsamples[samples]);
if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/1))
return 1;
sprintf(fn, "rt-%u-%u-%u.w64", channels, bits_per_sample, nsamples[samples]);
flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.w64", channels, bits_per_sample, nsamples[samples]);
if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/2))
return 1;
if(bits_per_sample % 8 == 0) {
sprintf(fn, "rt-%u-%u-%u.raw", channels, bits_per_sample, nsamples[samples]);
flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.raw", channels, bits_per_sample, nsamples[samples]);
if(!generate_raw(fn, channels, bits_per_sample/8, nsamples[samples]))
return 1;
}