From 7450bd283f0082fe1b3499142ad5273067db70c6 Mon Sep 17 00:00:00 2001 From: Michael Roitzsch Date: Tue, 27 Jul 2004 18:06:45 +0000 Subject: from the docs of sprintf: "when the strings overlap, the behaviour is undefined" (actually it works with glibc and sprintf, but not with snprintf) CVS patchset: 6859 CVS date: 2004/07/27 18:06:45 --- src/input/input_cdda.c | 16 ++++++++++------ src/libsputext/demux_sputext.c | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index 2f5638db6..4b3c40d92 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -20,7 +20,7 @@ * Compact Disc Digital Audio (CDDA) Input Plugin * by Mike Melanson (melanson@pcisys.net) * - * $Id: input_cdda.c,v 1.62 2004/07/25 17:11:59 mroi Exp $ + * $Id: input_cdda.c,v 1.63 2004/07/27 18:06:45 mroi Exp $ */ #ifdef HAVE_CONFIG_H @@ -1219,7 +1219,8 @@ static void _cdda_mkdir_recursive_safe(xine_t *xine, char *path) { if (*buf2 != '\0') { #endif - snprintf(buf2, sizeof(buf2), "%s/%s", buf2, p); + int size = strlen(buf2); + snprintf(buf2 + size, sizeof(buf2) - size, "/%s", p); #ifdef WIN32 } @@ -1358,8 +1359,9 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) { if(!strcasecmp(pdir->d_name, discid)) { FILE *fd; + int size = strlen(cdir); - snprintf(cdir, sizeof(cdir), "%s/%s", cdir, discid); + snprintf(cdir + size, sizeof(cdir) - size, "/%s", discid); if((fd = fopen(cdir, "r")) == NULL) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_cdda: fopen(%s) failed: %s.\n", cdir, strerror(errno)); @@ -1572,9 +1574,10 @@ static int _cdda_cddb_retrieve(cdda_input_plugin_t *this) { memset(&buffer, 0, sizeof(buffer)); sprintf(buffer, "cddb query %08lx %d ", this->cddb.disc_id, this->cddb.num_tracks); for (i = 0; i < this->cddb.num_tracks; i++) { - snprintf(buffer, sizeof(buffer), "%s%d ", buffer, this->cddb.track[i].start); + int size = strlen(buffer); + snprintf(buffer + size, sizeof(buffer) - size, "%d ", this->cddb.track[i].start); } - snprintf(buffer, sizeof(buffer), "%s%d\n", buffer, this->cddb.disc_length); + snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer), "%d\n", this->cddb.disc_length); if ((err = _cdda_cddb_send_command(this, buffer)) <= 0) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_cdda: error while sending cddb query command.\n"); @@ -1628,10 +1631,11 @@ static int _cdda_cddb_retrieve(cdda_input_plugin_t *this) { while (strcmp(buffer, ".")) { char buf[2048]; int tnum; + int bufsize = strlen(buffercache); memset(&buffer, 0, sizeof(buffer)); _cdda_cddb_socket_read(this, buffer, sizeof(buffer) - 1); - snprintf(buffercache, sizeof(buffercache), "%s%s\n", buffercache, buffer); + snprintf(buffercache + bufsize, sizeof(buffercache) - bufsize, "%s\n", buffer); if (sscanf(buffer, "DTITLE=%s", &buf[0]) == 1) { char *pt, *artist, *title; diff --git a/src/libsputext/demux_sputext.c b/src/libsputext/demux_sputext.c index 2d14b2edc..30ffb3bd7 100644 --- a/src/libsputext/demux_sputext.c +++ b/src/libsputext/demux_sputext.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: demux_sputext.c,v 1.37 2004/07/22 14:19:12 mroi Exp $ + * $Id: demux_sputext.c,v 1.38 2004/07/27 18:06:46 mroi Exp $ * * code based on old libsputext/xine_decoder.c * @@ -1159,9 +1159,9 @@ static subtitle_t *sub_read_file (demux_sputext_t *this) { sprintf(buffer, "Read %i subtitles", this->num); if(this->errs) - sprintf(buffer, "%s, %i bad line(s).\n", buffer, this->errs); + sprintf(buffer + strlen(buffer), ", %i bad line(s).\n", this->errs); else - sprintf(buffer, "%s%c", buffer, '\n'); + strcat(buffer, "\n"); xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, buffer); } -- cgit v1.2.3