From 4055622a3f6f631beb81639a6e45b9f759fa8af8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Wed, 30 Jun 1999 11:34:54 -0700
Subject: [PATCH] changed behaviour of %c use %1c to get old behaviour

Rev: src/modules/sprintf/sprintf.c:1.39
---
 src/modules/sprintf/sprintf.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/modules/sprintf/sprintf.c b/src/modules/sprintf/sprintf.c
index 12e4b63349..4ca6a0102e 100644
--- a/src/modules/sprintf/sprintf.c
+++ b/src/modules/sprintf/sprintf.c
@@ -99,7 +99,7 @@
 */
 
 #include "global.h"
-RCSID("$Id: sprintf.c,v 1.38 1999/06/17 20:31:52 noring Exp $");
+RCSID("$Id: sprintf.c,v 1.39 1999/06/30 18:34:54 hubbe Exp $");
 #include "error.h"
 #include "array.h"
 #include "svalue.h"
@@ -964,17 +964,28 @@ static void low_pike_sprintf(struct string_builder *r,
         INT32 l,tmp;
 	char *x;
         DO_OP();
-        l=1;
-        if(fsp->width > 0) l=fsp->width;
-	x=(char *)alloca(l);
-	fsp->b=MKPCHARP(x,0);
-	fsp->len=l;
-	GET_INT(tmp);
-        while(--l>=0)
-        {
-          x[l]=tmp & 0xff;
-          tmp>>=8;
-        }
+	if(fsp->width == SPRINTF_UNDECIDED)
+	{
+	  GET_INT(tmp);
+	  x=(char *)alloca(4);
+	  if(tmp<256) fsp->b=MKPCHARP(x,0);
+	  else if(tmp<65536) fsp->b=MKPCHARP(x,1);
+	  else  fsp->b=MKPCHARP(x,2);
+	  SET_INDEX_PCHARP(fsp->b,0,tmp);
+	  fsp->len=1;
+	}else{
+	  l=1;
+	  if(fsp->width > 0) l=fsp->width;
+	  x=(char *)alloca(l);
+	  fsp->b=MKPCHARP(x,0);
+	  fsp->len=l;
+	  GET_INT(tmp);
+	  while(--l>=0)
+	  {
+	    x[l]=tmp & 0xff;
+	    tmp>>=8;
+	  }
+	}
 	break;
       }
 
-- 
GitLab