On 19/04/2007, at 15:58, Chad MILLER wrote:
>
> Tabs again. :\ ':set expandtabs" if you're using vi.
>
I think I got rid of all the tabs this time.
> I hate to see the magical value "17". I'm ashamed to see it in the
> surrounding code.
>
> But, in this case, it's not the same "17" -- the others are
> locations to represent numbers, whereas this is padding. "%09000d"
> is at least legal, though unlikely, right? That would try to write
> 8983 bytes past the end of buffz.
>
> I suggest making a for-loop and write chunks of padding or (I don't
> like as much) use my_alloca() to allocate one up front, and pack
> it, and then write it.
I went for allocating space. Here it goes
http://people.warp.es/~koke/patches/27894-fix-printf_3.diff
--
Jorge Bernal Ordovás <jbernal@stripped>
http://amedias.org/ [ES]
http://koke.amedias.org/ [EN]
MySQL Instructor & Systems Developer
Warp Networks http://www.warp.es/
D. Jaime I 33 3º Dcha, 50001 Zaragoza, Spain
--- mysql-5.1-trunk/mysys/mf_iocache2.c 2007-02-24 02:43:10.000000000 -0800
+++ mysql-5.1/mysys/mf_iocache2.c 2007-04-19 16:56:29.000000000 -0700
@@ -299,6 +299,7 @@
uint minimum_width; /* as yet unimplemented */
uint minimum_width_sign;
uint precision; /* as yet unimplemented for anything but %b */
+ my_bool is_zero_padded;
/*
Store the location of the beginning of a format directive, for the
@@ -337,8 +338,10 @@
minimum_width= 0;
precision= 0;
minimum_width_sign= 1;
+ is_zero_padded= FALSE;
/* Skip if max size is used (to be compatible with printf) */
while (*fmt == '-') { fmt++; minimum_width_sign= -1; }
+ while (*fmt == '0') { fmt++; is_zero_padded= TRUE; }
if (*fmt == '*') {
precision= (int) va_arg(args, int);
fmt++;
@@ -390,6 +393,18 @@
length2= (uint) (int10_to_str((long) iarg,buff, -10) - buff);
else
length2= (uint) (int10_to_str((long) (uint) iarg,buff,10)- buff);
+ if (minimum_width > length2)
+ {
+ char *buffz;
+
+ buffz = my_alloca(minimum_width - length2);
+ if (is_zero_padded)
+ memset(buffz, '0', minimum_width - length2);
+ else
+ memset(buffz, ' ', minimum_width - length2);
+ my_b_write(info, buffz, minimum_width - length2);
+ my_afree(buffz);
+ }
out_length+= length2;
if (my_b_write(info, buff, length2))
goto err;