Purge more strcpy/strcat usage.

This commit is contained in:
Erik de Castro Lopo 2013-04-01 22:00:59 +11:00
parent 36c1f08564
commit 932c7ba26c
4 changed files with 17 additions and 10 deletions

View File

@ -189,7 +189,12 @@
*
* This function wraps the MS version to behave more like the the ISO version.
*/
#ifdef __cplusplus
extern "C" {
#endif
int flac_snprintf(char *str, size_t size, const char *fmt, ...);
#ifdef __cplusplus
};
#endif
#endif /* FLAC__SHARE__COMPAT_H */

View File

@ -39,6 +39,7 @@
#include "share/grabbag.h"
#include "share/compat.h"
#include "share/macros.h"
#include "share/safe_str.h"
extern "C" {
#include "test_libs_common/file_utils_flac.h"
}
@ -202,11 +203,11 @@ void add_to_padding_length_(unsigned index, int delta)
bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
{
static const char *tempfile_suffix = ".metadata_edit";
size_t destlen = strlen(filename) + strlen(tempfile_suffix) + 1;
if(0 == (*tempfilename = (char*)malloc(strlen(filename) + strlen(tempfile_suffix) + 1)))
if(0 == (*tempfilename = (char*)malloc(destlen)))
return false;
strcpy(*tempfilename, filename);
strcat(*tempfilename, tempfile_suffix);
flac_snprintf(*tempfilename, destlen, "%s%s", filename, tempfile_suffix);
if(0 == (*tempfile = flac_fopen(*tempfilename, "wb")))
return false;
@ -533,7 +534,7 @@ static bool generate_file_(bool include_extras, bool is_ogg)
if (0 == (cuesheet = ::FLAC__metadata_object_new(::FLAC__METADATA_TYPE_CUESHEET)))
return die_("priming our metadata");
cuesheet->is_last = false;
strcpy(cuesheet->data.cue_sheet.media_catalog_number, "bogo-MCN");
safe_strncpy(cuesheet->data.cue_sheet.media_catalog_number, "bogo-MCN", sizeof(cuesheet->data.cue_sheet.media_catalog_number));
cuesheet->data.cue_sheet.lead_in = 123;
cuesheet->data.cue_sheet.is_cd = false;
if (!FLAC__metadata_object_cuesheet_insert_blank_track(cuesheet, 0))

View File

@ -16,11 +16,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "FLAC/assert.h"
#include "FLAC++/metadata.h"
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcmp() */
#include "FLAC/assert.h"
#include "FLAC++/metadata.h"
#include "share/safe_str.h"
static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application_, vorbiscomment_, cuesheet_, picture_;
@ -1694,7 +1695,7 @@ bool test_metadata_object_cuesheet()
{
char mcn[129];
memset(mcn, 0, sizeof(mcn));
strcpy(mcn, "1234567890123");
safe_strncpy(mcn, "1234567890123", sizeof(mcn));
block.set_media_catalog_number(mcn);
if(0 != memcmp(block.get_media_catalog_number(), mcn, sizeof(mcn)))
return die_("value mismatch");

View File

@ -106,8 +106,8 @@ int main(int argc, char *argv[])
args[0] = '\0';
for(i = 0; i < argc; i++) {
if(i > 0)
strcat(args, " ");
strcat(args, argv[i]);
safe_strncat(args, sizeof(args), " ");
safe_strncat(args, sizeof(args), argv[i]);
}
//fprintf(stderr, "@@@ cmd=[%s] args=[%s]\n", argv[0], args);