changeset 30404:5fbb30fa62cc

Fix newline removal code that might read and write out of bounds.
author reimar
date Wed, 27 Jan 2010 19:42:24 +0000
parents 22633d3fbffe
children d39acea63f2e
files gui/skin/font.c gui/skin/skin.c
diffstat 2 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/gui/skin/font.c	Wed Jan 27 19:15:49 2010 +0000
+++ b/gui/skin/font.c	Wed Jan 27 19:42:24 2010 +0000
@@ -87,8 +87,8 @@
   {
    fgets( tmp,255,f ); linenumber++;
 
-   c=tmp[ strlen( tmp ) - 1 ]; if ( ( c == '\n' )||( c == '\r' ) ) tmp[ strlen( tmp ) - 1 ]=0;
-   c=tmp[ strlen( tmp ) - 1 ]; if ( ( c == '\n' )||( c == '\r' ) ) tmp[ strlen( tmp ) - 1 ]=0;
+   // remove any kind of newline, if any
+   tmp[strcspn(tmp, "\n\r")] = 0;
    for ( c=0;c < (int)strlen( tmp );c++ )
      if ( tmp[c] == ';' ) { tmp[c]=0; break; }
    if ( !tmp[0] ) continue;
--- a/gui/skin/skin.c	Wed Jan 27 19:15:49 2010 +0000
+++ b/gui/skin/skin.c	Wed Jan 27 19:42:24 2010 +0000
@@ -717,8 +717,8 @@
   {
    linenumber++;
 
-   c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0;
-   c=tmp[ strlen( tmp ) - 1 ]; if ( c == '\n' || c == '\r' ) tmp[ strlen( tmp ) - 1 ]=0;
+   // remove any kind of newline, if any
+   tmp[strcspn(tmp, "\n\r")] = 0;
    for ( c=0;c<(int)strlen( tmp );c++ )
     if ( tmp[c] == ';' )
      {