Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit fix buffer growing code.



details:   https://anonhg.NetBSD.org/src/rev/c50254e28e40
branches:  trunk
changeset: 767679:c50254e28e40
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jul 27 02:18:30 2011 +0000

description:
fix buffer growing code.

diffstat:

 lib/libedit/chartype.c |  23 ++++++++---------------
 1 files changed, 8 insertions(+), 15 deletions(-)

diffs (52 lines):

diff -r 30d8b89f1ad6 -r c50254e28e40 lib/libedit/chartype.c
--- a/lib/libedit/chartype.c    Wed Jul 27 02:18:00 2011 +0000
+++ b/lib/libedit/chartype.c    Wed Jul 27 02:18:30 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chartype.c,v 1.4 2010/04/15 00:55:57 christos Exp $    */
+/*     $NetBSD: chartype.c,v 1.5 2011/07/27 02:18:30 christos Exp $    */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: chartype.c,v 1.4 2010/04/15 00:55:57 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.5 2011/07/27 02:18:30 christos Exp $");
 #endif /* not lint && not SCCSID */
 #include "el.h"
 #include <stdlib.h>
@@ -89,27 +89,20 @@
 
        dst = conv->cbuff;
        while (*s) {
-               used = ct_encode_char(dst, (int)(conv->csize -
-                   (dst - conv->cbuff)), *s);
-               if (used == -1) { /* failed to encode, need more buffer space */
+               used = conv->csize - (dst - conv->cbuff);
+               if (used < 5) {
                        used = dst - conv->cbuff;
                        ct_conv_buff_resize(conv, conv->csize + CT_BUFSIZ, 0);
                        if (!conv->cbuff)
                                return NULL;
                        dst = conv->cbuff + used;
-                       /* don't increment s here - we want to retry it! */
                }
-               else
-                       ++s;
+               used = ct_encode_char(dst, 5, *s);
+               if (used == -1) /* failed to encode, need more buffer space */
+                       abort();
+               ++s;
                dst += used;
        }
-       if (dst >= (conv->cbuff + conv->csize)) {
-               used = dst - conv->cbuff;
-               ct_conv_buff_resize(conv, conv->csize + 1, 0);
-               if (!conv->cbuff)
-                       return NULL;
-               dst = conv->cbuff + used;
-       }
        *dst = '\0';
        return conv->cbuff;
 }



Home | Main Index | Thread Index | Old Index