From 84279b817db5e9fba0b31bd2f759af5dc4289e87 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Sun, 9 May 2010 08:54:06 +0200 Subject: [PATCH] Kill two open-coded instances of safe_atou32() --- src/filescanner_ffmpeg.c | 18 +++--------------- src/filescanner_urlfile.c | 33 +++++---------------------------- 2 files changed, 8 insertions(+), 43 deletions(-) diff --git a/src/filescanner_ffmpeg.c b/src/filescanner_ffmpeg.c index 8eddf05f..079e78ab 100644 --- a/src/filescanner_ffmpeg.c +++ b/src/filescanner_ffmpeg.c @@ -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; } } } diff --git a/src/filescanner_urlfile.c b/src/filescanner_urlfile.c index 1945c90b..558473b4 100644 --- a/src/filescanner_urlfile.c +++ b/src/filescanner_urlfile.c @@ -27,11 +27,11 @@ #include #include #include -#include #include #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);