> On Mon, Feb 21, 2005 at 10:53:08PM -0500, Bruce Momjian wrote:
>
> Applied.

Thanks a lot. The patch attached solves the tread
safety problem. Please review it before applying, 
I am not sure I am doing the right thing


On Tue, 22 Feb 2005 19:57:15 +0100, Kurt Roeckx <[EMAIL PROTECTED]> wrote:
> The configure test is a little broken.  It needs to quote the
> $'s.
> 
> I've rewritten the test a little.

This one needs applying too. $'s do get scrambled.

Best regards, 
Nicolai.
*** ./src/port/snprintf.c.orig	sali Şub 22 20:02:03 2005
--- ./src/port/snprintf.c	sali Şub 22 21:59:48 2005
***************
*** 80,96 ****
   * for string length.  This covers a nasty loophole.
   *
   * The other functions are there to prevent NULL pointers from
!  * causing nast effects.
   **************************************************************/
  
  /*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.6 2005/02/22 04:57:24 momjian Exp $";*/
- static char *end;
- static int	SnprfOverflow;
  
  int			snprintf(char *str, size_t count, const char *fmt,...);
  int			vsnprintf(char *str, size_t count, const char *fmt, va_list args);
  int			printf(const char *format, ...);
! static void dopr(char *buffer, const char *format, va_list args);
  
  int
  printf(const char *fmt,...)
--- 80,94 ----
   * for string length.  This covers a nasty loophole.
   *
   * The other functions are there to prevent NULL pointers from
!  * causing nasty effects.
   **************************************************************/
  
  /*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.6 2005/02/22 04:57:24 momjian Exp $";*/
  
  int			snprintf(char *str, size_t count, const char *fmt,...);
  int			vsnprintf(char *str, size_t count, const char *fmt, va_list args);
  int			printf(const char *format, ...);
! static void 		dopr(char *buffer, const char *format, va_list args, char *end);
  
  int
  printf(const char *fmt,...)
***************
*** 97,103 ****
  {
  	int			len;
  	va_list			args;
! 	static char*		buffer[4096];
  	char*			p;
  
  	va_start(args, fmt);
--- 95,101 ----
  {
  	int			len;
  	va_list			args;
! 	char*		buffer[4096];
  	char*			p;
  
  	va_start(args, fmt);
***************
*** 125,134 ****
  int
  vsnprintf(char *str, size_t count, const char *fmt, va_list args)
  {
  	str[0] = '\0';
  	end = str + count - 1;
! 	SnprfOverflow = 0;
! 	dopr(str, fmt, args);
  	if (count > 0)
  		end[0] = '\0';
  	return strlen(str);
--- 123,132 ----
  int
  vsnprintf(char *str, size_t count, const char *fmt, va_list args)
  {
+ 	char *end;
  	str[0] = '\0';
  	end = str + count - 1;
! 	dopr(str, fmt, args, end);
  	if (count > 0)
  		end[0] = '\0';
  	return strlen(str);
***************
*** 138,148 ****
   * dopr(): poor man's version of doprintf
   */
  
! static void fmtstr(char *value, int ljust, int len, int zpad, int maxwidth);
! static void fmtnum(long_long value, int base, int dosign, int ljust, int len, int zpad);
! static void fmtfloat(double value, char type, int ljust, int len, int precision, int pointflag);
! static void dostr(char *str, int cut);
! static void dopr_outch(int c);
  
  static char *output;
  
--- 136,146 ----
   * dopr(): poor man's version of doprintf
   */
  
! static void fmtstr(char *value, int ljust, int len, int zpad, int maxwidth, char *end);
! static void fmtnum(long_long value, int base, int dosign, int ljust, int len, int zpad, char *end);
! static void fmtfloat(double value, char type, int ljust, int len, int precision, int pointflag, char *end);
! static void dostr(char *str, int cut, char *end);
! static void dopr_outch(int c, char *end);
  
  static char *output;
  
***************
*** 152,158 ****
  #define	FMTCHAR		4
  
  static void
! dopr(char *buffer, const char *format, va_list args)
  {
  	int			ch;
  	long_long	value;
--- 150,156 ----
  #define	FMTCHAR		4
  
  static void
! dopr(char *buffer, const char *format, va_list args, char *end)
  {
  	int			ch;
  	long_long	value;
***************
*** 415,425 ****
  					case '%':
  						break;
  					default:
! 						dostr("???????", 0);
  				}
  				break;
  			default:
! 				dopr_outch(ch);
  				break;
  		}
  	}
--- 413,423 ----
  					case '%':
  						break;
  					default:
! 						dostr("???????", 0, end);
  				}
  				break;
  			default:
! 				dopr_outch(ch, end);
  				break;
  		}
  	}
***************
*** 446,465 ****
  				case FMTSTR:
  					fmtstr(fmtparptr[i]->value, fmtparptr[i]->ljust,
  						fmtparptr[i]->len, fmtparptr[i]->zpad,
! 						fmtparptr[i]->maxwidth);
  					break;
  				case FMTNUM:
  					fmtnum(fmtparptr[i]->numvalue, fmtparptr[i]->base,
  						fmtparptr[i]->dosign, fmtparptr[i]->ljust,
! 						fmtparptr[i]->len, fmtparptr[i]->zpad);
  					break;
  				case FMTFLOAT:
  					fmtfloat(fmtparptr[i]->fvalue, fmtparptr[i]->type,
  						fmtparptr[i]->ljust, fmtparptr[i]->len,
! 						fmtparptr[i]->precision, fmtparptr[i]->pointflag);
  					break;
  				case FMTCHAR:
! 					dopr_outch(fmtparptr[i]->charvalue);
  					break;
  				}
  				format = fmtpar[i].fmtend;
--- 444,464 ----
  				case FMTSTR:
  					fmtstr(fmtparptr[i]->value, fmtparptr[i]->ljust,
  						fmtparptr[i]->len, fmtparptr[i]->zpad,
! 						fmtparptr[i]->maxwidth, end);
  					break;
  				case FMTNUM:
  					fmtnum(fmtparptr[i]->numvalue, fmtparptr[i]->base,
  						fmtparptr[i]->dosign, fmtparptr[i]->ljust,
! 						fmtparptr[i]->len, fmtparptr[i]->zpad, end);
  					break;
  				case FMTFLOAT:
  					fmtfloat(fmtparptr[i]->fvalue, fmtparptr[i]->type,
  						fmtparptr[i]->ljust, fmtparptr[i]->len,
! 						fmtparptr[i]->precision, fmtparptr[i]->pointflag,
! 						end);
  					break;
  				case FMTCHAR:
! 					dopr_outch(fmtparptr[i]->charvalue, end);
  					break;
  				}
  				format = fmtpar[i].fmtend;
***************
*** 466,472 ****
  				goto nochar;
  			}
  		}
! 		dopr_outch(ch);
  nochar:
  	/* nothing */
  	; /* semicolon required because a goto has to be attached to a statement */
--- 465,471 ----
  				goto nochar;
  			}
  		}
! 		dopr_outch(ch, end);
  nochar:
  	/* nothing */
  	; /* semicolon required because a goto has to be attached to a statement */
***************
*** 475,481 ****
  }
  
  static void
! fmtstr(char *value, int ljust, int len, int zpad, int maxwidth)
  {
  	int			padlen,
  				strlen;			/* amount to pad */
--- 474,480 ----
  }
  
  static void
! fmtstr(char *value, int ljust, int len, int zpad, int maxwidth, char *end)
  {
  	int			padlen,
  				strlen;			/* amount to pad */
***************
*** 492,510 ****
  		padlen = -padlen;
  	while (padlen > 0)
  	{
! 		dopr_outch(' ');
  		--padlen;
  	}
! 	dostr(value, maxwidth);
  	while (padlen < 0)
  	{
! 		dopr_outch(' ');
  		++padlen;
  	}
  }
  
  static void
! fmtnum(long_long value, int base, int dosign, int ljust, int len, int zpad)
  {
  	int			signvalue = 0;
  	ulong_long	uvalue;
--- 491,509 ----
  		padlen = -padlen;
  	while (padlen > 0)
  	{
! 		dopr_outch(' ', end);
  		--padlen;
  	}
! 	dostr(value, maxwidth, end);
  	while (padlen < 0)
  	{
! 		dopr_outch(' ', end);
  		++padlen;
  	}
  }
  
  static void
! fmtnum(long_long value, int base, int dosign, int ljust, int len, int zpad, char *end)
  {
  	int			signvalue = 0;
  	ulong_long	uvalue;
***************
*** 559,592 ****
  	{
  		if (signvalue)
  		{
! 			dopr_outch(signvalue);
  			--padlen;
  			signvalue = 0;
  		}
  		while (padlen > 0)
  		{
! 			dopr_outch(zpad);
  			--padlen;
  		}
  	}
  	while (padlen > 0)
  	{
! 		dopr_outch(' ');
  		--padlen;
  	}
  	if (signvalue)
! 		dopr_outch(signvalue);
  	while (place > 0)
! 		dopr_outch(convert[--place]);
  	while (padlen < 0)
  	{
! 		dopr_outch(' ');
  		++padlen;
  	}
  }
  
  static void
! fmtfloat(double value, char type, int ljust, int len, int precision, int pointflag)
  {
  	char		fmt[32];
  	char		convert[512];
--- 558,591 ----
  	{
  		if (signvalue)
  		{
! 			dopr_outch(signvalue, end);
  			--padlen;
  			signvalue = 0;
  		}
  		while (padlen > 0)
  		{
! 			dopr_outch(zpad, end);
  			--padlen;
  		}
  	}
  	while (padlen > 0)
  	{
! 		dopr_outch(' ', end);
  		--padlen;
  	}
  	if (signvalue)
! 		dopr_outch(signvalue, end);
  	while (place > 0)
! 		dopr_outch(convert[--place], end);
  	while (padlen < 0)
  	{
! 		dopr_outch(' ', end);
  		++padlen;
  	}
  }
  
  static void
! fmtfloat(double value, char type, int ljust, int len, int precision, int pointflag, char *end)
  {
  	char		fmt[32];
  	char		convert[512];
***************
*** 613,646 ****
  
  	while (padlen > 0)
  	{
! 		dopr_outch(' ');
  		--padlen;
  	}
! 	dostr(convert, 0);
  	while (padlen < 0)
  	{
! 		dopr_outch(' ');
  		++padlen;
  	}
  }
  
  static void
! dostr(char *str, int cut)
  {
  	if (cut)
  	{
  		while (*str && cut-- > 0)
! 			dopr_outch(*str++);
  	}
  	else
  	{
  		while (*str)
! 			dopr_outch(*str++);
  	}
  }
  
  static void
! dopr_outch(int c)
  {
  #ifdef NOT_USED
  	if (iscntrl((unsigned char) c) && c != '\n' && c != '\t')
--- 612,645 ----
  
  	while (padlen > 0)
  	{
! 		dopr_outch(' ', end);
  		--padlen;
  	}
! 	dostr(convert, 0, end);
  	while (padlen < 0)
  	{
! 		dopr_outch(' ', end);
  		++padlen;
  	}
  }
  
  static void
! dostr(char *str, int cut, char *end)
  {
  	if (cut)
  	{
  		while (*str && cut-- > 0)
! 			dopr_outch(*str++, end);
  	}
  	else
  	{
  		while (*str)
! 			dopr_outch(*str++, end);
  	}
  }
  
  static void
! dopr_outch(int c, char *end)
  {
  #ifdef NOT_USED
  	if (iscntrl((unsigned char) c) && c != '\n' && c != '\t')
***************
*** 652,657 ****
  #endif
  	if (end == 0 || output < end)
  		*output++ = c;
- 	else
- 		SnprfOverflow++;
  }
--- 651,654 ----
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to