This replaces un-safe usage of sprintf() and Micorsoft's _snprintf()
with something sane.
}
/* write the subframe */
}
/* write the subframe */
- sprintf(outfilename, "f%06u.s%u.gp", frame_number, channel);
+ flac_snprintf(outfilename, sizeof (outfilename), "f%06u.s%u.gp", frame_number, channel);
compute_stats(&stats);
(void)dump_stats(&stats, outfilename);
compute_stats(&stats);
(void)dump_stats(&stats, outfilename);
# include <config.h>
#endif
# include <config.h>
#endif
-#include "utils.h"
-#include "FLAC/assert.h"
-#include "FLAC/metadata.h"
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "utils.h"
+#include "FLAC/assert.h"
+#include "FLAC/metadata.h"
+#include "share/compat.h"
const char *CHANNEL_MASK_TAG = "WAVEFORMATEXTENSIBLE_CHANNEL_MASK";
const char *CHANNEL_MASK_TAG = "WAVEFORMATEXTENSIBLE_CHANNEL_MASK";
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
FLAC__ASSERT(strlen(CHANNEL_MASK_TAG+1+2+16+1) <= sizeof(tag)); /* +1 for =, +2 for 0x, +16 for digits, +1 for NUL */
entry.entry = (FLAC__byte*)tag;
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
FLAC__ASSERT(strlen(CHANNEL_MASK_TAG+1+2+16+1) <= sizeof(tag)); /* +1 for =, +2 for 0x, +16 for digits, +1 for NUL */
entry.entry = (FLAC__byte*)tag;
-#if defined _MSC_VER || defined __MINGW32__
- if((entry.length = _snprintf(tag, sizeof(tag), "%s=0x%04X", CHANNEL_MASK_TAG, (unsigned)channel_mask)) >= sizeof(tag))
-#else
- if((entry.length = snprintf(tag, sizeof(tag), "%s=0x%04X", CHANNEL_MASK_TAG, (unsigned)channel_mask)) >= sizeof(tag))
-#endif
+ if((entry.length = flac_snprintf(tag, sizeof(tag), "%s=0x%04X", CHANNEL_MASK_TAG, (unsigned)channel_mask)) >= sizeof(tag))
return false;
if(!FLAC__metadata_object_vorbiscomment_replace_comment(object, entry, /*all=*/true, /*copy=*/true))
return false;
return false;
if(!FLAC__metadata_object_vorbiscomment_replace_comment(object, entry, /*all=*/true, /*copy=*/true))
return false;
#endif
#include <errno.h>
#endif
#include <errno.h>
-#include <stdio.h> /* for snprintf() */
#include <string.h>
#include "options.h"
#include "utils.h"
#include <string.h>
#include "options.h"
#include "utils.h"
for(track = 0; track < cs->num_tracks; track++) {
const FLAC__StreamMetadata_CueSheet_Track *tr = cs->tracks+track;
for(index = 0; index < tr->num_indices; index++) {
for(track = 0; track < cs->num_tracks; track++) {
const FLAC__StreamMetadata_CueSheet_Track *tr = cs->tracks+track;
for(index = 0; index < tr->num_indices; index++) {
- sprintf(spec, "%" PRIu64 ";", (tr->offset + tr->indices[index].offset));
+ flac_snprintf(spec, sizeof (spec), "%" PRIu64 ";", (tr->offset + tr->indices[index].offset));
local_strcat(seekpoint_specification, spec);
}
}
local_strcat(seekpoint_specification, spec);
}
}
-#if defined _MSC_VER || defined __MINGW32__
- _snprintf(ref, reflen, "\"%s\" FLAC", filename);
-#else
- snprintf(ref, reflen, "\"%s\" FLAC", filename);
-#endif
+ flac_snprintf(ref, reflen, "\"%s\" FLAC", filename);
grabbag__cuesheet_emit(f, cuesheet, ref);
grabbag__cuesheet_emit(f, cuesheet, ref);
return -4;
/* build the command to call flac with */
return -4;
/* build the command to call flac with */
- sprintf(prog, "%sflac.exe", macdir);
- sprintf(options, "-%d", flac_level);
+ flac_snprintf(prog, sizeof (prog), "%sflac.exe", macdir);
+ flac_snprintf(options, sizeof (options), "-%d", flac_level);
for(i = opt_arg; i < argc; i++)
if(argv[i][0] == '-') {
strcat(options, " ");
strcat(options, argv[i]);
}
for(i = opt_arg; i < argc; i++)
if(argv[i][0] == '-') {
strcat(options, " ");
strcat(options, argv[i]);
}
- sprintf(cmdline, "\"%s\" %s -o \"%s\" \"%s\"", prog, options, argv[to_arg], argv[from_arg]);
+ flac_snprintf(cmdline, sizeof (cmdline), "\"%s\" %s -o \"%s\" \"%s\"", prog, options, argv[to_arg], argv[from_arg]);
flac_return_val = execit(prog, cmdline);
flac_return_val = execit(prog, cmdline);
}
strcpy(strrchr(to,'.'), ".flac");
}
strcpy(strrchr(to,'.'), ".flac");
- sprintf(prog, "%sflac_ren.exe", macdir);
- sprintf(cmdline, "\"%s\" \"%s\" \"%s\"", prog, from, to);
+ flac_snprintf(prog, sizeof (prog), "%sflac_ren.exe", macdir);
+ flac_snprintf(cmdline, sizeof (smdline), "\"%s\" \"%s\" \"%s\"", prog, from, to);
flac_return_val = forkit(prog, cmdline);
}
flac_return_val = forkit(prog, cmdline);
}
{
udp_port = udp_establish_listener (&udp_sock);
if (udp_port > 0)
{
udp_port = udp_establish_listener (&udp_sock);
if (udp_port > 0)
- sprintf (udpspace, "x-audiocast-udpport: %d\r\n", udp_port);
+ flac_snprintf (udpspace, sizeof (udpspace), "x-audiocast-udpport: %d\r\n", udp_port);
else if (strstr(lines[i], "x-audiocast-udpseqnr:") != NULL)
{
gchar obuf[60];
else if (strstr(lines[i], "x-audiocast-udpseqnr:") != NULL)
{
gchar obuf[60];
- sprintf(obuf, "x-audiocast-ack: %ld \r\n", atol(valptr));
+ flac_snprintf(obuf, sizeof (obuf), "x-audiocast-ack: %ld \r\n", atol(valptr));
if (sendto(sock, obuf, strlen(obuf), 0, (struct sockaddr *) &from, fromlen) < 0)
{
g_log(NULL, G_LOG_LEVEL_WARNING,
if (sendto(sock, obuf, strlen(obuf), 0, (struct sockaddr *) &from, fromlen) < 0)
{
g_log(NULL, G_LOG_LEVEL_WARNING,
- *title = g_malloc(strlen(errtitle) + 1 + strlen(filename) + 1 + 1);
- sprintf(*title, "%s\"%s\"", errtitle, filename);
+ size_t len = strlen(errtitle) + 1 + strlen(filename) + 1 + 1;
+ *title = g_malloc(len);
+ flac_snprintf(*title, len, "%s\"%s\"", errtitle, filename);
}
} else {
*title = NULL;
}
} else {
*title = NULL;
if (0 == saved_locale)
return false;
setlocale(LC_ALL, "C");
if (0 == saved_locale)
return false;
setlocale(LC_ALL, "C");
-#if defined _MSC_VER || defined __MINGW32__
- _snprintf(buffer, sizeof(buffer)-1, format, name, value);
-#else
- snprintf(buffer, sizeof(buffer)-1, format, name, value);
-#endif
+ flac_snprintf(buffer, sizeof(buffer), format, name, value);
setlocale(LC_ALL, saved_locale);
free(saved_locale);
setlocale(LC_ALL, saved_locale);
free(saved_locale);
FLAC__metadata_object_delete(cuesheet);
return 1;
}
FLAC__metadata_object_delete(cuesheet);
return 1;
}
- sprintf(tmpfilename, "%s.1", infilename);
+ flac_snprintf(tmpfilename, sizeof (tmpfilename), "%s.1", infilename);
if(0 == (fout = fopen(tmpfilename, "w"))) {
fprintf(stderr, "can't open file %s for writing: %s\n", tmpfilename, strerror(errno));
FLAC__metadata_object_delete(cuesheet);
if(0 == (fout = fopen(tmpfilename, "w"))) {
fprintf(stderr, "can't open file %s for writing: %s\n", tmpfilename, strerror(errno));
FLAC__metadata_object_delete(cuesheet);
FLAC__metadata_object_delete(cuesheet);
return 1;
}
FLAC__metadata_object_delete(cuesheet);
return 1;
}
- sprintf(tmpfilename, "%s.2", infilename);
+ flac_snprintf(tmpfilename, sizeof (tmpfilename), "%s.2", infilename);
if(0 == (fout = fopen(tmpfilename, "w"))) {
fprintf(stderr, "can't open file %s for writing: %s\n", tmpfilename, strerror(errno));
FLAC__metadata_object_delete(cuesheet);
if(0 == (fout = fopen(tmpfilename, "w"))) {
fprintf(stderr, "can't open file %s for writing: %s\n", tmpfilename, strerror(errno));
FLAC__metadata_object_delete(cuesheet);
const char *error;
char s[4096];
if(fn_only)
const char *error;
char s[4096];
if(fn_only)
-#if defined _MSC_VER || defined __MINGW32__
- _snprintf(s, sizeof(s)-1, "%s/%s", prefix, pf->path);
-#else
- snprintf(s, sizeof(s)-1, "%s/%s", prefix, pf->path);
-#endif
+ flac_snprintf(s, sizeof(s), "%s/%s", prefix, pf->path);
-#if defined _MSC_VER || defined __MINGW32__
- _snprintf(s, sizeof(s)-1, "%u|%s|%s|%s|%s/%s", (unsigned)pf->type, pf->mime_type, pf->description, res, prefix, pf->path);
-#else
- snprintf(s, sizeof(s)-1, "%u|%s|%s|%s|%s/%s", (unsigned)pf->type, pf->mime_type, pf->description, res, prefix, pf->path);
-#endif
+ flac_snprintf(s, sizeof(s), "%u|%s|%s|%s|%s/%s", (unsigned)pf->type, pf->mime_type, pf->description, res, prefix, pf->path);
printf("testing grabbag__picture_parse_specification(\"%s\")... ", s);
if(0 == (obj = grabbag__picture_parse_specification(s, &error)))
printf("testing grabbag__picture_parse_specification(\"%s\")... ", s);
if(0 == (obj = grabbag__picture_parse_specification(s, &error)))
test_streams_SOURCES = \
main.c
test_streams_SOURCES = \
main.c
-test_streams_LDADD = -lm
+test_streams_LDADD = $(top_builddir)/src/share/grabbag/libgrabbag.la -lm
#endif
#include "FLAC/assert.h"
#include "FLAC/ordinals.h"
#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?) */
#ifndef M_PI
/* math.h in VC++ doesn't seem to have this (how Microsoft is that?) */
for(samples = 0; samples < sizeof(nsamples)/sizeof(nsamples[0]); samples++) {
char fn[64];
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;
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;
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;
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) {
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;
}
if(!generate_raw(fn, channels, bits_per_sample/8, nsamples[samples]))
return 1;
}