[Cbe-oss-dev] [PATCH 3/3] libspe,libspe2: Fix C99 gets() handler

Kazunori Asayama asayama at sm.sony.co.jp
Wed Jan 31 20:50:42 EST 2007


Attached is a patch to fix the following bug of gets() in libspe and
libspe2:

  - gets() does not remove a trailing line-feed character.

----
Index: libspe2/spebase/default_c99_handler.c
===================================================================
--- libspe2.orig/spebase/default_c99_handler.c
+++ libspe2/spebase/default_c99_handler.c
@@ -1508,13 +1508,19 @@ int default_c99_handler_gets(char *ls, u
     FILE *stream;
     char *s, *r;
     int rc;
+    int size;
 
     DEBUG_PRINTF("%s\n", __func__);
     CHECK_C99_OPCODE(GETS);
     stream = get_FILE(SPE_STDIN);
     s = GET_LS_PTR(arg0->slot[0]);
-    r = fgets(s, LS_SIZE - arg0->slot[0], stream);
+    size = LS_SIZE - arg0->slot[0];
+    r = fgets(s, size, stream);
     rc = (r == s) ? arg0->slot[0] : 0;
+    if (r == s) { /* remove trailing linefeed character. */
+      char *p = memchr(s, '\n', size);
+      if (p) *p = '\0';
+    }
     PUT_LS_RC(rc, 0, 0, errno);
     return 0;
 }



More information about the cbe-oss-dev mailing list