Re: [Plib-devel] Re: [PATCH] ssg/ssgLoadAC.cxx: fix potential crash; accept DOS line endings
Brought to you by:
sjbaker
From: Frederic B. <fr...@wa...> - 2003-07-04 21:07:42
|
Frederic Bouvier writes: > > This patch produces this on MSVC : > > Compiling... > ssgLoadAC.cxx > ssgLoadAC.cxx(352) : error C2057: expected constant expression > ssgLoadAC.cxx(352) : error C2466: cannot allocate an array of constant size > 0 > ssgLoadAC.cxx(352) : error C2133: 'buffer' : unknown size > > line 352 is : > char buffer [ len + 3 ] ; /* data + \r + \n + \0 */ > > > It seems to not allow allocation of a static array with a variable size. I propose the patch below. It avoids a strcpy at the expense of two bytes : -Fred RCS file: /cvsroot/plib/plib/src/ssg/ssgLoadAC.cxx,v retrieving revision 1.31 diff -u -r1.31 ssgLoadAC.cxx --- ssgLoadAC.cxx 4 Jul 2003 13:51:58 -0000 1.31 +++ ssgLoadAC.cxx 4 Jul 2003 21:03:58 -0000 @@ -349,12 +349,10 @@ static int do_data ( char *s ) { int len = strtol ( s, NULL, 0 ) ; - char buffer [ len + 3 ] ; /* data + \r + \n + \0 */ - fgets ( buffer, len + 3, loader_fd ) ; - current_data = new char [ len + 1 ] ; + current_data = new char [ len + 3 ] ; + fgets ( current_data, len + 3, loader_fd ) ; - strncpy ( current_data, buffer, len ) ; current_data [ len ] = '\0' ; ssgBranch *br = current_options -> createBranch ( current_data ) ; |