From 5bc68f0ed1fa690a566ec8cd3c2c93a30b940708 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Tue, 15 Jun 2010 18:10:19 +0200
Subject: [PATCH] Fixed buffer overrun in string_builder_putchars().

Fixed minor code redundancy issue.

Rev: src/stralloc.c:1.239
---
 src/stralloc.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/src/stralloc.c b/src/stralloc.c
index 5a34d61632..4354a74f85 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: stralloc.c,v 1.238 2010/05/28 17:37:52 mast Exp $
+|| $Id: stralloc.c,v 1.239 2010/06/15 16:10:19 grubba Exp $
 */
 
 #include "global.h"
@@ -2317,12 +2317,9 @@ PMOD_EXPORT void string_builder_putchar(struct string_builder *s, int ch)
   ptrdiff_t i;
   int mag = min_magnitude(ch);
 
-  if (mag > s->s->size_shift) {
-    string_build_mkspace(s, 1, mag);
+  string_build_mkspace(s, 1, mag);
+  if (mag > s->known_shift) {
     s->known_shift = mag;
-  } else if (((size_t)s->s->len) >= ((size_t)s->malloced)) {
-    string_build_mkspace(s, 1, mag);
-    s->known_shift = MAXIMUM(mag, s->known_shift);
   }
   i = s->s->len++;
   low_set_index(s->s,i,ch);
@@ -2336,12 +2333,9 @@ PMOD_EXPORT void string_builder_putchars(struct string_builder *s, int ch,
   ptrdiff_t len = s->s->len;
   int mag = min_magnitude(ch);
 
-  if (mag > s->s->size_shift) {
-    string_build_mkspace(s, count, mag);
+  string_build_mkspace(s, count, mag);
+  if (mag > s->known_shift) {
     s->known_shift = mag;
-  } else if (((size_t)s->s->len) >= ((size_t)s->malloced)) {
-    string_build_mkspace(s, count, mag);
-    s->known_shift = MAXIMUM(mag, s->known_shift);
   }
 
   switch (s->s->size_shift) {
-- 
GitLab