Skip to content

Commit 44a5c58

Browse files
committed
Added realloc error checking in convert_fcm function to fix cppcheck warning.
1 parent b938511 commit 44a5c58

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/oldmovie.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static uint8 joop[4];
4848
static uint8 joopcmd;
4949
static uint32 framets = 0;
5050
static uint32 frameptr = 0;
51-
static uint8* moviedata = NULL;
51+
static uint8* moviedata = nullptr;
5252
static uint32 moviedatasize = 0;
5353
static uint32 firstframeoffset = 0;
5454
static uint32 savestate_offset = 0;
@@ -626,7 +626,19 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname)
626626
//ResetInputTypes();
627627

628628
fp->fseek(firstframeoffset,SEEK_SET);
629-
moviedata = (uint8*)realloc(moviedata, moviedatasize);
629+
uint8 *newMovieData = (uint8*)realloc(moviedata, moviedatasize);
630+
if (newMovieData)
631+
{
632+
moviedata = newMovieData;
633+
}
634+
else
635+
{
636+
if (moviedata)
637+
{
638+
free(moviedata); moviedata = nullptr;
639+
}
640+
return FCM_CONVERTRESULT_REALLOC_FAIL;
641+
}
630642
fp->fread((char*)moviedata,moviedatasize);
631643

632644
frameptr = 0;
@@ -669,8 +681,11 @@ EFCM_CONVERTRESULT convert_fcm(MovieData& md, std::string fname)
669681
md.ports[0] = md.ports[1] = SI_GAMEPAD;
670682
}
671683

672-
free(moviedata);
673-
moviedata = 0;
684+
if (moviedata)
685+
{
686+
free(moviedata);
687+
moviedata = nullptr;
688+
}
674689

675690
delete fp;
676691
return FCM_CONVERTRESULT_SUCCESS;

src/oldmovie.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ enum EFCM_CONVERTRESULT
1010
FCM_CONVERTRESULT_OLDVERSION,
1111
FCM_CONVERTRESULT_UNSUPPORTEDVERSION,
1212
FCM_CONVERTRESULT_STARTFROMSAVESTATENOTSUPPORTED,
13+
FCM_CONVERTRESULT_REALLOC_FAIL,
1314
};
1415

1516
inline const char * EFCM_CONVERTRESULT_message(EFCM_CONVERTRESULT e)

0 commit comments

Comments
 (0)