[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r9734: snprintf is barely better tha
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r9734: snprintf is barely better than printf and isn't at all standard. Use |
Date: |
Sun, 14 Sep 2008 12:39:05 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9734
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Sun 2008-09-14 12:39:05 +0200
message:
snprintf is barely better than printf and isn't at all standard. Use
stringstreams instead. Use strncpy to copy data into a C string.
modified:
libmedia/ffmpeg/sound_handler_sdl.cpp
plugin/plugin.cpp
------------------------------------------------------------
revno: 9733.1.1
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Sun 2008-09-14 12:13:01 +0200
message:
I don't think we need to reimplement std::strncpy.
modified:
libmedia/ffmpeg/sound_handler_sdl.cpp
------------------------------------------------------------
revno: 9733.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Sun 2008-09-14 12:13:18 +0200
message:
Don't use snprintf, which doesn't appear anywhere in the C++ standard.
Stringstreams are correct here.
modified:
plugin/plugin.cpp
=== modified file 'libmedia/ffmpeg/sound_handler_sdl.cpp'
--- a/libmedia/ffmpeg/sound_handler_sdl.cpp 2008-09-09 04:34:06 +0000
+++ b/libmedia/ffmpeg/sound_handler_sdl.cpp 2008-09-14 10:13:01 +0000
@@ -721,23 +721,15 @@
// write a wave header, using the current audioSpec settings
void SDL_sound_handler::write_wave_header(std::ofstream& outfile)
{
-
- int i;
- char obuff[80];
// allocate wav header
WAV_HDR wav;
CHUNK_HDR chk;
// setup wav header
- snprintf(obuff, sizeof(obuff), "RIFF");
- for(i=0;i<4;i++) wav.rID[i] = obuff[i];
-
- snprintf(obuff, sizeof(obuff), "WAVE");
- for(i=0;i<4;i++) wav.wID[i] = obuff[i];
-
- snprintf(obuff, sizeof(obuff), "fmt ");
- for(i=0;i<4;i++) wav.fId[i] = obuff[i];
+ std::strncpy(wav.rID, "RIFF", 4);
+ std::strncpy(wav.wID, "WAVE", 4);
+ std::strncpy(wav.fId, "fmt ", 4);
wav.nBitsPerSample = ((audioSpec.format == AUDIO_S16SYS) ? 16 : 0);
wav.nSamplesPerSec = audioSpec.freq;
@@ -752,8 +744,7 @@
wav.nBlockAlign = audioSpec.channels * wav.nBitsPerSample / 8;
// setup chunk header
- snprintf(obuff, sizeof(obuff), "data");
- for(i=0;i<4;i++) chk.dId[i] = obuff[i];
+ std::strncpy(chk.dId, "data", 4);
chk.dLen = 0;
/* write riff/wav header */
=== modified file 'plugin/plugin.cpp'
--- a/plugin/plugin.cpp 2008-09-12 21:18:45 +0000
+++ b/plugin/plugin.cpp 2008-09-14 10:13:18 +0000
@@ -794,12 +794,12 @@
*/
// Prepare width, height and window ID variables
- const size_t buf_size = 30;
- char xid[buf_size], width[buf_size], height[buf_size], hostfd[buf_size];
- snprintf(xid, buf_size, "%ld", win);
- snprintf(width, buf_size, "%d", _width);
- snprintf(height, buf_size, "%d", _height);
- snprintf(hostfd, buf_size, "%d", c2p_pipe[1]);
+ std::ostringstream xid, width, height, hostfd;
+
+ xid << win;
+ width << _width;
+ height << _height;
+ hostfd << c2p_pipe[1];
// Prepare Actionscript variables (e.g. Flashvars).
vector<string> paramvalues;
@@ -839,13 +839,13 @@
// X window ID (necessary for gnash to function as a plugin)
argv[argc++] = "-x";
- argv[argc++] = xid;
+ argv[argc++] = xid.str().c_str();
// Height and width
argv[argc++] = "-j";
- argv[argc++] = width;
+ argv[argc++] = width.str().c_str();
argv[argc++] = "-k";
- argv[argc++] = height;
+ argv[argc++] = height.str().c_str();
// Url of the root movie
argv[argc++] = "-u";
@@ -853,7 +853,7 @@
// Host FD
argv[argc++] = "-F";
- argv[argc++] = hostfd;
+ argv[argc++] = hostfd.str().c_str();
// Base URL is the page that the SWF is embedded in. It is
// by Gnash for resolving relative URLs in the movie. If the
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r9734: snprintf is barely better than printf and isn't at all standard. Use,
Benjamin Wolsey <=