[v4,5/8] mesa/main: don't use win _vsnprintf. there is 'util_vsnprintf' function

Submitted by andrey simiklit on Sept. 6, 2018, 2:43 p.m.

Details

Message ID 1536245039-22231-6-git-send-email-asimiklit.work@gmail.com
State New
Headers show
Series "mesa/util: add missing va_end() after va_copy()" ( rev: 8 ) in Mesa

Not browsing as part of any series.

Commit Message

andrey simiklit Sept. 6, 2018, 2:43 p.m.
From: Andrii Simiklit <andrii.simiklit@globallogic.com>

The win '_vsnprintf' function incompatibility with C99 vsnprintf.
At least for case when the input buffer size less than the required size:
'_vsnprintf' returns -1 for this case.
'vsnprintf' returns the required size.

So use cross platform implementation 'util_vsnprintf'.

Fixes: 2353e96c320d "Coerce vsnprintf to _vsnprintf for windows"
Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com>
---
 src/mesa/main/imports.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index b4685b6..d42825e 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -46,6 +46,7 @@ 
 #include <stdarg.h>
 #include "c99_math.h"
 #include "util/rounding.h" /* for _mesa_roundeven */
+#include "util/u_string.h"
 #include "imports.h"
 #include "context.h"
 #include "version.h"
@@ -58,9 +59,7 @@ 
 #endif
 
 
-#ifdef _WIN32
-#define vsnprintf _vsnprintf
-#elif defined(__IBMC__) || defined(__IBMCPP__)
+#if defined(__IBMC__) || defined(__IBMCPP__)
 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
 #endif
 
@@ -255,7 +254,7 @@  _mesa_bitcount_64(uint64_t n)
 int
 _mesa_vsnprintf(char *str, size_t size, const char *fmt, va_list args)
 {
-   return vsnprintf( str, size, fmt, args);
+   return util_vsnprintf( str, size, fmt, args);
 }
 
 /** Wrapper around vsnprintf() */
@@ -264,8 +263,8 @@  _mesa_snprintf( char *str, size_t size, const char *fmt, ... )
 {
    int r;
    va_list args;
-   va_start( args, fmt );  
-   r = vsnprintf( str, size, fmt, args );
+   va_start( args, fmt );
+   r = util_vsnprintf( str, size, fmt, args );
    va_end( args );
    return r;
 }

Comments

It seems like it might better to just replace all the calllers of
_mesa_*printf with util_*printf.

On 09/06/2018 07:43 AM, asimiklit.work@gmail.com wrote:
> From: Andrii Simiklit <andrii.simiklit@globallogic.com>
> 
> The win '_vsnprintf' function incompatibility with C99 vsnprintf.
> At least for case when the input buffer size less than the required size:
> '_vsnprintf' returns -1 for this case.
> 'vsnprintf' returns the required size.
> 
> So use cross platform implementation 'util_vsnprintf'.
> 
> Fixes: 2353e96c320d "Coerce vsnprintf to _vsnprintf for windows"
> Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com>
> ---
>  src/mesa/main/imports.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
> index b4685b6..d42825e 100644
> --- a/src/mesa/main/imports.c
> +++ b/src/mesa/main/imports.c
> @@ -46,6 +46,7 @@
>  #include <stdarg.h>
>  #include "c99_math.h"
>  #include "util/rounding.h" /* for _mesa_roundeven */
> +#include "util/u_string.h"
>  #include "imports.h"
>  #include "context.h"
>  #include "version.h"
> @@ -58,9 +59,7 @@
>  #endif
>  
>  
> -#ifdef _WIN32
> -#define vsnprintf _vsnprintf
> -#elif defined(__IBMC__) || defined(__IBMCPP__)
> +#if defined(__IBMC__) || defined(__IBMCPP__)
>  extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
>  #endif
>  
> @@ -255,7 +254,7 @@ _mesa_bitcount_64(uint64_t n)
>  int
>  _mesa_vsnprintf(char *str, size_t size, const char *fmt, va_list args)
>  {
> -   return vsnprintf( str, size, fmt, args);
> +   return util_vsnprintf( str, size, fmt, args);
>  }
>  
>  /** Wrapper around vsnprintf() */
> @@ -264,8 +263,8 @@ _mesa_snprintf( char *str, size_t size, const char *fmt, ... )
>  {
>     int r;
>     va_list args;
> -   va_start( args, fmt );  
> -   r = vsnprintf( str, size, fmt, args );
> +   va_start( args, fmt );
> +   r = util_vsnprintf( str, size, fmt, args );
>     va_end( args );
>     return r;
>  }
>
On Fri, Sep 7, 2018 at 5:38 AM Ian Romanick <idr@freedesktop.org> wrote:

> It seems like it might better to just replace all the calllers of
> _mesa_*printf with util_*printf.
>

Thanks. Yes you're right. I am going to rework it today.


> On 09/06/2018 07:43 AM, asimiklit.work@gmail.com wrote:
> > From: Andrii Simiklit <andrii.simiklit@globallogic.com>
> >
> > The win '_vsnprintf' function incompatibility with C99 vsnprintf.
> > At least for case when the input buffer size less than the required size:
> > '_vsnprintf' returns -1 for this case.
> > 'vsnprintf' returns the required size.
> >
> > So use cross platform implementation 'util_vsnprintf'.
> >
> > Fixes: 2353e96c320d "Coerce vsnprintf to _vsnprintf for windows"
> > Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com>
> > ---
> >  src/mesa/main/imports.c | 11 +++++------
> >  1 file changed, 5 insertions(+), 6 deletions(-)
> >
> > diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
> > index b4685b6..d42825e 100644
> > --- a/src/mesa/main/imports.c
> > +++ b/src/mesa/main/imports.c
> > @@ -46,6 +46,7 @@
> >  #include <stdarg.h>
> >  #include "c99_math.h"
> >  #include "util/rounding.h" /* for _mesa_roundeven */
> > +#include "util/u_string.h"
> >  #include "imports.h"
> >  #include "context.h"
> >  #include "version.h"
> > @@ -58,9 +59,7 @@
> >  #endif
> >
> >
> > -#ifdef _WIN32
> > -#define vsnprintf _vsnprintf
> > -#elif defined(__IBMC__) || defined(__IBMCPP__)
> > +#if defined(__IBMC__) || defined(__IBMCPP__)
> >  extern int vsnprintf(char *str, size_t count, const char *fmt, va_list
> arg);
> >  #endif
> >
> > @@ -255,7 +254,7 @@ _mesa_bitcount_64(uint64_t n)
> >  int
> >  _mesa_vsnprintf(char *str, size_t size, const char *fmt, va_list args)
> >  {
> > -   return vsnprintf( str, size, fmt, args);
> > +   return util_vsnprintf( str, size, fmt, args);
> >  }
> >
> >  /** Wrapper around vsnprintf() */
> > @@ -264,8 +263,8 @@ _mesa_snprintf( char *str, size_t size, const char
> *fmt, ... )
> >  {
> >     int r;
> >     va_list args;
> > -   va_start( args, fmt );
> > -   r = vsnprintf( str, size, fmt, args );
> > +   va_start( args, fmt );
> > +   r = util_vsnprintf( str, size, fmt, args );
> >     va_end( args );
> >     return r;
> >  }
> >
>
>