From d1ab9dbc5f0c35aa10ee0c67b9dc2eb6fd31dd13 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Fri, 25 Feb 2011 15:25:42 +0100 Subject: Now checking the result of all realloc() calls --- epg.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'epg.c') diff --git a/epg.c b/epg.c index 18d91fc7..c2d1783d 100644 --- a/epg.c +++ b/epg.c @@ -7,7 +7,7 @@ * Original version (as used in VDR before 1.3.0) written by * Robert Schneider and Rolf Hakenes . * - * $Id: epg.c 2.6 2010/02/28 14:24:55 kls Exp $ + * $Id: epg.c 2.7 2011/02/25 15:16:05 kls Exp $ */ #include "epg.h" @@ -56,25 +56,34 @@ cComponents::~cComponents(void) free(components); } -void cComponents::Realloc(int Index) +bool cComponents::Realloc(int Index) { if (Index >= numComponents) { - int n = numComponents; - numComponents = Index + 1; - components = (tComponent *)realloc(components, numComponents * sizeof(tComponent)); - memset(&components[n], 0, sizeof(tComponent) * (numComponents - n)); + Index++; + if (tComponent *NewBuffer = (tComponent *)realloc(components, Index * sizeof(tComponent))) { + int n = numComponents; + numComponents = Index; + components = NewBuffer; + memset(&components[n], 0, sizeof(tComponent) * (numComponents - n)); + } + else { + esyslog("ERROR: out of memory"); + return false; + } } + return true; } void cComponents::SetComponent(int Index, const char *s) { - Realloc(Index); - components[Index].FromString(s); + if (Realloc(Index)) + components[Index].FromString(s); } void cComponents::SetComponent(int Index, uchar Stream, uchar Type, const char *Language, const char *Description) { - Realloc(Index); + if (!Realloc(Index)) + return; tComponent *p = &components[Index]; p->stream = Stream; p->type = Type; -- cgit v1.2.3