mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
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:
@@ -152,7 +152,7 @@ void flac__analyze_frame(const FLAC__Frame *frame, unsigned frame_number, FLAC__
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
@@ -20,14 +20,15 @@
|
||||
# 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 "utils.h"
|
||||
#include "FLAC/assert.h"
|
||||
#include "FLAC/metadata.h"
|
||||
#include "share/compat.h"
|
||||
|
||||
const char *CHANNEL_MASK_TAG = "WAVEFORMATEXTENSIBLE_CHANNEL_MASK";
|
||||
|
||||
@@ -285,11 +286,7 @@ FLAC__bool flac__utils_set_channel_mask_tag(FLAC__StreamMetadata *object, FLAC__
|
||||
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;
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h> /* for snprintf() */
|
||||
#include <string.h>
|
||||
#include "options.h"
|
||||
#include "utils.h"
|
||||
@@ -163,7 +162,7 @@ FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet,
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -201,11 +200,7 @@ FLAC__bool export_cs_to(const char *filename, const FLAC__StreamMetadata *cueshe
|
||||
return false;
|
||||
}
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
@@ -100,14 +100,14 @@ int main(int argc, char *argv[])
|
||||
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]);
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -139,8 +139,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ static int http_connect (gchar *url_, gboolean head, guint64 offset)
|
||||
{
|
||||
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
|
||||
udp_sock = 0;
|
||||
}
|
||||
@@ -879,7 +879,7 @@ static int udp_check_for_data(int sock)
|
||||
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,
|
||||
|
||||
@@ -402,8 +402,9 @@ void FLAC_XMMS__get_song_info(char *filename, char **title, int *length_in_msec)
|
||||
*title = NULL;
|
||||
}
|
||||
else {
|
||||
*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;
|
||||
|
||||
@@ -102,11 +102,7 @@ static FLAC__bool append_tag_(FLAC__StreamMetadata *block, const char *format, 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);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ static int do_cuesheet(const char *infilename, unsigned sample_rate, FLAC__bool
|
||||
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);
|
||||
@@ -95,7 +95,7 @@ static int do_cuesheet(const char *infilename, unsigned sample_rate, FLAC__bool
|
||||
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);
|
||||
|
||||
@@ -70,17 +70,9 @@ static FLAC__bool test_one_picture(const char *prefix, const PictureFile *pf, co
|
||||
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);
|
||||
else
|
||||
#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)))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user