Kill two open-coded instances of safe_atou32()

This commit is contained in:
Julien BLACHE 2010-05-09 08:54:06 +02:00
parent 1a829d69a0
commit 84279b817d
2 changed files with 8 additions and 43 deletions

View File

@ -195,10 +195,9 @@ extract_metadata_core(struct media_file_info *mfi, AVMetadata *md, const struct
AVMetadataTag *mdt;
char **strval;
uint32_t *intval;
char *endptr;
long tmpval;
int mdcount;
int i;
int ret;
#if 0
/* Dump all the metadata reported by ffmpeg */
@ -240,20 +239,9 @@ extract_metadata_core(struct media_file_info *mfi, AVMetadata *md, const struct
if (*intval == 0)
{
errno = 0;
tmpval = strtol(mdt->value, &endptr, 10);
if (((errno == ERANGE) && ((tmpval == LONG_MAX) || (tmpval == LONG_MIN)))
|| ((errno != 0) && (tmpval == 0)))
ret = safe_atou32(mdt->value, intval);
if (ret < 0)
continue;
if (endptr == mdt->value)
continue;
if (tmpval > UINT32_MAX)
continue;
*intval = (uint32_t) tmpval;
}
}
}

View File

@ -27,11 +27,11 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <errno.h>
#include "logger.h"
#include "db.h"
#include "misc.h"
#include "filescanner.h"
@ -43,7 +43,7 @@ scan_url_file(char *file, struct media_file_info *mfi)
char *tail;
char buf[256];
size_t len;
long intval;
int ret;
DPRINTF(E_DBG, L_SCAN, "Getting URL file info\n");
@ -101,39 +101,16 @@ scan_url_file(char *file, struct media_file_info *mfi)
mfi->title = strdup(head);
mfi->url = strdup(tail + 1);
errno = 0;
intval = strtol(buf, &tail, 10);
if (((errno == ERANGE) && ((intval == LONG_MAX) || (intval == LONG_MIN)))
|| ((errno != 0) && (intval == 0)))
ret = safe_atou32(buf, &mfi->bitrate);
if (ret < 0)
{
DPRINTF(E_WARN, L_SCAN, "Could not read bitrate: %s\n", strerror(errno));
DPRINTF(E_WARN, L_SCAN, "Could not read bitrate\n");
free(mfi->title);
free(mfi->url);
return -1;
}
if (tail == buf)
{
DPRINTF(E_WARN, L_SCAN, "No bitrate found\n");
free(mfi->title);
free(mfi->url);
return -1;
}
if (intval > INT_MAX)
{
DPRINTF(E_WARN, L_SCAN, "Bitrate too large\n");
free(mfi->title);
free(mfi->url);
return -1;
}
mfi->bitrate = (int)intval;
DPRINTF(E_DBG, L_SCAN," Title: %s\n", mfi->title);
DPRINTF(E_DBG, L_SCAN," Bitrate: %d\n", mfi->bitrate);
DPRINTF(E_DBG, L_SCAN," URL: %s\n", mfi->url);