* Use an asprintf wrapper, to report errors and NULLify the result.

This commit is contained in:
Justin Maggard
2012-03-14 17:57:21 +00:00
parent c9d979886b
commit cabbd0b1de
10 changed files with 77 additions and 53 deletions

View File

@ -258,7 +258,7 @@ parse_nfo(const char * path, metadata_t * m)
{
val2 = GetValueFromNameValueList(&xml, "episodetitle");
if( val2 )
asprintf(&m->title, "%s - %s", val, val2);
xasprintf(&m->title, "%s - %s", val, val2);
else
m->title = strdup(val);
}
@ -419,8 +419,8 @@ GetAudioMetadata(const char * path, char * name)
if( song.dlna_pn )
m.dlna_pn = strdup(song.dlna_pn);
if( song.year )
asprintf(&m.date, "%04d-01-01", song.year);
asprintf(&m.duration, "%d:%02d:%02d.%03d",
xasprintf(&m.date, "%04d-01-01", song.year);
xasprintf(&m.duration, "%d:%02d:%02d.%03d",
(song.song_length/3600000),
(song.song_length/60000%60),
(song.song_length/1000%60),
@ -630,10 +630,7 @@ GetImageMetadata(const char * path, char * name)
break;
}
if( rotate )
{
if( asprintf(&m.rotation, "%d", rotate) < 0 )
m.rotation = NULL;
}
xasprintf(&m.rotation, "%d", rotate);
}
if( ed->size )
@ -691,7 +688,7 @@ no_exifdata:
m.dlna_pn = strdup("JPEG_MED");
else if( (width <= 4096 && height <= 4096) || !(GETFLAG(DLNA_STRICT_MASK)) )
m.dlna_pn = strdup("JPEG_LRG");
asprintf(&m.resolution, "%dx%d", width, height);
xasprintf(&m.resolution, "%dx%d", width, height);
ret = sql_exec(db, "INSERT into DETAILS"
" (PATH, TITLE, SIZE, TIMESTAMP, DATE, RESOLUTION,"
@ -881,13 +878,13 @@ GetVideoMetadata(const char * path, char * name)
DPRINTF(E_DEBUG, L_METADATA, "Unhandled audio codec [0x%X]\n", ac->codec_id);
break;
}
asprintf(&m.frequency, "%u", ac->sample_rate);
xasprintf(&m.frequency, "%u", ac->sample_rate);
#if LIBAVCODEC_VERSION_INT < (52<<16)
asprintf(&m.bps, "%u", ac->bits_per_sample);
xasprintf(&m.bps, "%u", ac->bits_per_sample);
#else
asprintf(&m.bps, "%u", ac->bits_per_coded_sample);
xasprintf(&m.bps, "%u", ac->bits_per_coded_sample);
#endif
asprintf(&m.channels, "%u", ac->channels);
xasprintf(&m.channels, "%u", ac->channels);
}
if( vc )
{
@ -895,23 +892,23 @@ GetVideoMetadata(const char * path, char * name)
int duration, hours, min, sec, ms;
ts_timestamp_t ts_timestamp = NONE;
DPRINTF(E_DEBUG, L_METADATA, "Container: '%s' [%s]\n", ctx->iformat->name, basepath);
asprintf(&m.resolution, "%dx%d", vc->width, vc->height);
xasprintf(&m.resolution, "%dx%d", vc->width, vc->height);
if( ctx->bit_rate > 8 )
asprintf(&m.bitrate, "%u", ctx->bit_rate / 8);
xasprintf(&m.bitrate, "%u", ctx->bit_rate / 8);
if( ctx->duration > 0 ) {
duration = (int)(ctx->duration / AV_TIME_BASE);
hours = (int)(duration / 3600);
min = (int)(duration / 60 % 60);
sec = (int)(duration % 60);
ms = (int)(ctx->duration / (AV_TIME_BASE/1000) % 1000);
asprintf(&m.duration, "%d:%02d:%02d.%03d", hours, min, sec, ms);
xasprintf(&m.duration, "%d:%02d:%02d.%03d", hours, min, sec, ms);
}
/* NOTE: The DLNA spec only provides for ASF (WMV), TS, PS, and MP4 containers.
* Skip DLNA parsing for everything else. */
if( strcmp(ctx->iformat->name, "avi") == 0 )
{
asprintf(&m.mime, "video/x-msvideo");
xasprintf(&m.mime, "video/x-msvideo");
if( vc->codec_id == CODEC_ID_MPEG4 )
{
fourcc[0] = vc->codec_tag & 0xff;
@ -921,16 +918,16 @@ GetVideoMetadata(const char * path, char * name)
if( memcmp(fourcc, "XVID", 4) == 0 ||
memcmp(fourcc, "DX50", 4) == 0 ||
memcmp(fourcc, "DIVX", 4) == 0 )
asprintf(&m.creator, "DiVX");
xasprintf(&m.creator, "DiVX");
}
}
else if( strcmp(ctx->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") == 0 &&
ends_with(path, ".mov") )
asprintf(&m.mime, "video/quicktime");
xasprintf(&m.mime, "video/quicktime");
else if( strncmp(ctx->iformat->name, "matroska", 8) == 0 )
asprintf(&m.mime, "video/x-matroska");
xasprintf(&m.mime, "video/x-matroska");
else if( strcmp(ctx->iformat->name, "flv") == 0 )
asprintf(&m.mime, "video/x-flv");
xasprintf(&m.mime, "video/x-flv");
if( m.mime )
goto video_no_dlna;
@ -944,7 +941,7 @@ GetVideoMetadata(const char * path, char * name)
{
m.dlna_pn = strdup("MPEG1");
}
asprintf(&m.mime, "video/mpeg");
xasprintf(&m.mime, "video/mpeg");
}
break;
case CODEC_ID_MPEG2VIDEO:
@ -988,14 +985,14 @@ GetVideoMetadata(const char * path, char * name)
switch( ts_timestamp )
{
case NONE:
asprintf(&m.mime, "video/mpeg");
xasprintf(&m.mime, "video/mpeg");
if( m.dlna_pn )
off += sprintf(m.dlna_pn+off, "_ISO");
break;
case VALID:
off += sprintf(m.dlna_pn+off, "_T");
case EMPTY:
asprintf(&m.mime, "video/vnd.dlna.mpeg-tts");
xasprintf(&m.mime, "video/vnd.dlna.mpeg-tts");
default:
break;
}
@ -1010,7 +1007,7 @@ GetVideoMetadata(const char * path, char * name)
off += sprintf(m.dlna_pn+off, "PAL");
else
off += sprintf(m.dlna_pn+off, "NTSC");
asprintf(&m.mime, "video/mpeg");
xasprintf(&m.mime, "video/mpeg");
}
else
{
@ -1181,7 +1178,7 @@ GetVideoMetadata(const char * path, char * name)
case VALID:
off += sprintf(m.dlna_pn+off, "_T");
case EMPTY:
asprintf(&m.mime, "video/vnd.dlna.mpeg-tts");
xasprintf(&m.mime, "video/vnd.dlna.mpeg-tts");
default:
break;
}
@ -1345,7 +1342,7 @@ GetVideoMetadata(const char * path, char * name)
if( ends_with(path, ".3gp") )
{
asprintf(&m.mime, "video/3gpp");
xasprintf(&m.mime, "video/3gpp");
switch( audio_profile )
{
case PROFILE_AUDIO_AAC:
@ -1406,7 +1403,7 @@ GetVideoMetadata(const char * path, char * name)
m.dlna_pn = malloc(64);
off = sprintf(m.dlna_pn, "WMV");
DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is VC1\n", video_stream, basepath);
asprintf(&m.mime, "video/x-ms-wmv");
xasprintf(&m.mime, "video/x-ms-wmv");
if( (vc->width <= 176) &&
(vc->height <= 144) &&
(vc->level == 0) )
@ -1497,7 +1494,7 @@ GetVideoMetadata(const char * path, char * name)
}
break;
case CODEC_ID_MSMPEG4V3:
asprintf(&m.mime, "video/x-msvideo");
xasprintf(&m.mime, "video/x-msvideo");
default:
DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is %s [type %d]\n",
video_stream, basepath, m.resolution, vc->codec_id);
@ -1507,20 +1504,20 @@ GetVideoMetadata(const char * path, char * name)
if( !m.mime )
{
if( strcmp(ctx->iformat->name, "avi") == 0 )
asprintf(&m.mime, "video/x-msvideo");
xasprintf(&m.mime, "video/x-msvideo");
else if( strncmp(ctx->iformat->name, "mpeg", 4) == 0 )
asprintf(&m.mime, "video/mpeg");
xasprintf(&m.mime, "video/mpeg");
else if( strcmp(ctx->iformat->name, "asf") == 0 )
asprintf(&m.mime, "video/x-ms-wmv");
xasprintf(&m.mime, "video/x-ms-wmv");
else if( strcmp(ctx->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") == 0 )
if( ends_with(path, ".mov") )
asprintf(&m.mime, "video/quicktime");
xasprintf(&m.mime, "video/quicktime");
else
asprintf(&m.mime, "video/mp4");
xasprintf(&m.mime, "video/mp4");
else if( strncmp(ctx->iformat->name, "matroska", 8) == 0 )
asprintf(&m.mime, "video/x-matroska");
xasprintf(&m.mime, "video/x-matroska");
else if( strcmp(ctx->iformat->name, "flv") == 0 )
asprintf(&m.mime, "video/x-flv");
xasprintf(&m.mime, "video/x-flv");
else
DPRINTF(E_WARN, L_METADATA, "%s: Unhandled format: %s\n", path, ctx->iformat->name);
}