[Groonga-commit] groonga/groonga [master] [libedit] add error check for wcrtomb().

Back to archive index

null+****@clear***** null+****@clear*****
2011年 10月 12日 (水) 11:51:11 JST


Kouhei Sutou	2011-10-12 02:51:11 +0000 (Wed, 12 Oct 2011)

  New Revision: f1d030d1392f1cceca769438f6917aa7f0915158

  Log:
    [libedit] add error check for wcrtomb().

  Modified files:
    src/groonga.c

  Modified: src/groonga.c (+7 -1)
===================================================================
--- src/groonga.c    2011-10-12 02:46:15 +0000 (c46402b)
+++ src/groonga.c    2011-10-12 02:51:11 +0000 (1d8eedb)
@@ -195,7 +195,13 @@ prompt(grn_ctx *ctx, grn_obj *buf)
       wcrtomb(NULL, L'\0', &ps);
       for (i = 0; i < nchar; i++) {
         multibyte_len = wcrtomb(multibyte_buf, line[i], &ps);
-        GRN_TEXT_PUT(ctx, buf, multibyte_buf, multibyte_len);
+        if (multibyte_len == (size_t)-1) {
+          GRN_LOG(ctx, GRN_LOG_WARNING,
+                  "[prompt][libedit] failed to read input: %s", strerror(errno));
+          rc = GRN_INVALID_ARGUMENT;
+        } else {
+          GRN_TEXT_PUT(ctx, buf, multibyte_buf, multibyte_len);
+        }
       }
       rc = GRN_SUCCESS;
       len = GRN_TEXT_LEN(buf);




Groonga-commit メーリングリストの案内
Back to archive index