From ad678cf083430e92729ede882fcfa2ff0fa5a2b0 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 15 Mar 2016 14:13:45 +0100 Subject: MACOSX: Replace manual uint parsing by strtol. --- backends/audiocd/macosx/macosx-audiocd.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'backends') diff --git a/backends/audiocd/macosx/macosx-audiocd.cpp b/backends/audiocd/macosx/macosx-audiocd.cpp index ef5b4c453a..56075f2a60 100644 --- a/backends/audiocd/macosx/macosx-audiocd.cpp +++ b/backends/audiocd/macosx/macosx-audiocd.cpp @@ -44,6 +44,7 @@ #include #include +#include #include "common/scummsys.h" @@ -274,15 +275,20 @@ bool MacOSXAudioCDManager::findTrackNames(const Common::String &drivePath) { Common::String fileName = children[i].getName(); if (fileName.hasSuffix(".aiff") || fileName.hasSuffix(".cdda")) { - uint trackID = 0, j = 0; + uint j = 0; for (; j < fileName.size() && !Common::isDigit(fileName[j]); j++) ; - for (; j < fileName.size() && Common::isDigit(fileName[j]); j++) - trackID = trackID * 10 + (fileName[j] - '0'); + const char *trackIDString = fileName.c_str() + j; + char *endPtr = nullptr; + long trackID = strtol(trackIDString, &endPtr, 10); - _trackMap[trackID - 1] = drivePath + '/' + fileName; + if (trackIDString != endPtr && trackID > 0 && trackID < UINT_MAX) { + _trackMap[trackID - 1] = drivePath + '/' + fileName; + } else { + warning("Invalid track file name: '%s'", fileName.c_str()); + } } } } -- cgit v1.2.3