Remove __wur attribute for printf/scanf functions

Message ID CA180F4D0C023044AA10FB1BDCAC4D1F0175EE0A@EX01.evidente.local
State Rejected
Headers

Commit Message

Daniel Marjamäki Aug. 12, 2015, 9:38 a.m. UTC
  Hello!

Imho the __wur attribute should not be used on printf/scanf functions.

It is not insane to ignore the return value from these. these functions will perform the wanted I/O even though the return value is not used.

Best regards,
Daniel Marjamäki

..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden

Mobile:                 +46 (0)709 12 42 62
E-mail:                 Daniel.Marjamaki@evidente.se

www.evidente.se
  

Comments

Mike Frysinger Aug. 12, 2015, 9:59 a.m. UTC | #1
On 12 Aug 2015 09:38, Daniel Marjamäki wrote:
> Imho the __wur attribute should not be used on printf/scanf functions.
>
> It is not insane to ignore the return value from these. these functions will perform the wanted I/O even though the return value is not used.

you're confusing asprintf as a benign printf.  it is insane to not be checking 
the return value of that function.  it does memory allocation among other 
things.

as for the scanf family, see BZ #14254 and the thread from last time where we 
rejected this proposal:
https://sourceware.org/bugzilla/show_bug.cgi?id=14254
https://sourceware.org/ml/libc-alpha/2013-10/msg00290.html
-mike
  
Daniel Marjamäki Aug. 13, 2015, 8:20 a.m. UTC | #2
Hello!

> you're confusing asprintf as a benign printf

ok I guess so.


> as for the scanf family, see BZ #14254 and the thread from last time where we rejected this proposal:

thanks. however I am still not convinced. If I trust the input or think that 'garbage in => garbage out' is fine then ignoring the return value from scanf is ok.

I suggest a conservative approach that avoids FP; only use __wur if it's pointless or leads to UB to ignore the return value. calling strlen without using the return value would be pointless. calling fopen without taking the return value would probably lead to a resource leak.

If you still think that __wur should be used.. then let's keep it. I can live with the FP.

Best regards,
Daniel Marjamäki

..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden

Mobile:                 +46 (0)709 12 42 62
E-mail:                 Daniel.Marjamaki@evidente.se

www.evidente.se
  

Patch

diff --git a/libio/stdio.h b/libio/stdio.h
index 19ab0ae..2a5f4e7 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -398,13 +398,13 @@  __END_NAMESPACE_C99
    Store the address of the string in *PTR.  */
 extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
 		      _G_va_list __arg)
-     __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
+     __THROWNL __attribute__ ((__format__ (__printf__, 2, 0)));
 extern int __asprintf (char **__restrict __ptr,
 		       const char *__restrict __fmt, ...)
-     __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
+     __THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
 extern int asprintf (char **__restrict __ptr,
 		     const char *__restrict __fmt, ...)
-     __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
+     __THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
 #endif
 
 #ifdef __USE_XOPEN2K8
@@ -423,12 +423,12 @@  __BEGIN_NAMESPACE_STD
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
 extern int fscanf (FILE *__restrict __stream,
-		   const char *__restrict __format, ...) __wur;
+		   const char *__restrict __format, ...);
 /* Read formatted input from stdin.
 
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
-extern int scanf (const char *__restrict __format, ...) __wur;
+extern int scanf (const char *__restrict __format, ...);
 /* Read formatted input from S.  */
 extern int sscanf (const char *__restrict __s,
 		   const char *__restrict __format, ...) __THROW;
@@ -442,16 +442,16 @@  extern int sscanf (const char *__restrict __s,
    s, S or [.  */
 extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
 				const char *__restrict __format, ...),
-		       __isoc99_fscanf) __wur;
+		       __isoc99_fscanf);
 extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
-		       __isoc99_scanf) __wur;
+		       __isoc99_scanf);
 extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
 				    const char *__restrict __format, ...),
 			   __isoc99_sscanf);
 # else
 extern int __isoc99_fscanf (FILE *__restrict __stream,
-			    const char *__restrict __format, ...) __wur;
-extern int __isoc99_scanf (const char *__restrict __format, ...) __wur;
+			    const char *__restrict __format, ...);
+extern int __isoc99_scanf (const char *__restrict __format, ...);
 extern int __isoc99_sscanf (const char *__restrict __s,
 			    const char *__restrict __format, ...) __THROW;
 #  define fscanf __isoc99_fscanf
@@ -470,14 +470,14 @@  __BEGIN_NAMESPACE_C99
    marked with __THROW.  */
 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
 		    _G_va_list __arg)
-     __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
+     __attribute__ ((__format__ (__scanf__, 2, 0)));
 
 /* Read formatted input from stdin into argument list ARG.
 
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */
 extern int vscanf (const char *__restrict __format, _G_va_list __arg)
-     __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
+     __attribute__ ((__format__ (__scanf__, 1, 0)));
 
 /* Read formatted input from S into argument list ARG.  */
 extern int vsscanf (const char *__restrict __s,
@@ -495,10 +495,10 @@  extern int __REDIRECT (vfscanf,
 		       (FILE *__restrict __s,
 			const char *__restrict __format, _G_va_list __arg),
 		       __isoc99_vfscanf)
-     __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
+     __attribute__ ((__format__ (__scanf__, 2, 0)));
 extern int __REDIRECT (vscanf, (const char *__restrict __format,
 				_G_va_list __arg), __isoc99_vscanf)
-     __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
+     __attribute__ ((__format__ (__scanf__, 1, 0)));
 extern int __REDIRECT_NTH (vsscanf,
 			   (const char *__restrict __s,
 			    const char *__restrict __format,
@@ -507,9 +507,9 @@  extern int __REDIRECT_NTH (vsscanf,
 #  else
 extern int __isoc99_vfscanf (FILE *__restrict __s,
 			     const char *__restrict __format,
-			     _G_va_list __arg) __wur;
+			     _G_va_list __arg);
 extern int __isoc99_vscanf (const char *__restrict __format,
-			    _G_va_list __arg) __wur;
+			    _G_va_list __arg);
 extern int __isoc99_vsscanf (const char *__restrict __s,
 			     const char *__restrict __format,
 			     _G_va_list __arg) __THROW;