diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 51d84fae7..9a48b097d 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2012-02-15 Christopher Faylor + + * smallprint.cc (tmpbuf): Declare new class holding a static buffer, + protected by a lock. + (__small_vsprintf): Use tmpbuf to hold large buffer. + (__small_vswprintf): Ditto. + 2012-02-15 Corinna Vinschen * flock.cc (lf_setlock): Add timeout variable and set before calling diff --git a/winsup/cygwin/smallprint.cc b/winsup/cygwin/smallprint.cc index 9e59cc7b0..1ca7ca817 100644 --- a/winsup/cygwin/smallprint.cc +++ b/winsup/cygwin/smallprint.cc @@ -1,6 +1,7 @@ /* smallprint.cc: small print routines for WIN32 - Copyright 1996, 1998, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009 + Copyright 1996, 1998, 2000, 2001, 2002, 2003, 2005, 2006, + 2007, 2008, 2009, 2012 Red Hat, Inc. This file is part of Cygwin. @@ -11,6 +12,7 @@ details. */ #include "winsup.h" #include "ntdll.h" +#include "sync.h" #include #include #include @@ -23,6 +25,34 @@ details. */ static const char hex_str[] = "0123456789ABCDEF"; +class tmpbuf +{ + static WCHAR buf[NT_MAX_PATH]; + static muto lock; + bool locked; +public: + operator WCHAR * () + { + if (!locked) + { + lock.init ("smallprint_buf")->acquire (); + locked = true; + } + return buf; + } + operator char * () {return (char *) ((WCHAR *) *this);} + + tmpbuf (): locked (false) {}; + ~tmpbuf () + { + if (locked) + lock.release (); + } +}; + +WCHAR tmpbuf::buf[NT_MAX_PATH]; +muto tmpbuf::lock; + static char __fastcall * __rn (char *dst, int base, int dosign, long long val, int len, int pad, unsigned long long mask) { @@ -65,7 +95,7 @@ __rn (char *dst, int base, int dosign, long long val, int len, int pad, unsigned int __small_vsprintf (char *dst, const char *fmt, va_list ap) { - char tmp[NT_MAX_PATH]; + tmpbuf tmp; char *orig = dst; const char *s; PWCHAR w; @@ -367,7 +397,7 @@ __wrn (PWCHAR dst, int base, int dosign, long long val, int len, int pad, unsign int __small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap) { - WCHAR tmp[NT_MAX_PATH]; + tmpbuf tmp; PWCHAR orig = dst; const char *s; PWCHAR w;