Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Apr 2012 11:28:17 +0000 (UTC)
From:      Jean-Sebastien Pedron <dumbbell@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r234836 - head/lib/libc/stdio
Message-ID:  <201204301128.q3UBSHlb063816@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dumbbell
Date: Mon Apr 30 11:28:17 2012
New Revision: 234836
URL: http://svn.freebsd.org/changeset/base/234836

Log:
  Remove incorrect __restrict qualifier on several pointers
  
  The typical case was:
  static __inline int
  convert_ccl(FILE *fp, char * __restrict p, [...])
  {
          [...]
  
          if (p == SUPPRESS_PTR) {
  		[...]
  	} else {
  		[...]
  	}
  
  	[...]
  }
  
  This qualifier says that the pointer is the only one at that time
  pointing to the resource.
  
  Here, clang considers that "p" will never match "SUPPRESS_PTR" and
  optimize the if{} block out. This leads to segfaults in programs calling
  vfscanf(3) and vfwscanf(3) with just the format string (no arguments
  following it).
  
  The following softwares were reported to abort with segmentation fault
  and this patch fixes it:
      o  cmake
      o  smartd
      o  devel/ORBit2
  
  dim@ opened an LLVM PR to discuss this clang optimization:
      http://llvm.org/bugs/show_bug.cgi?id=12656
  
  Tested by:	bsam@

Modified:
  head/lib/libc/stdio/vfscanf.c
  head/lib/libc/stdio/vfwscanf.c

Modified: head/lib/libc/stdio/vfscanf.c
==============================================================================
--- head/lib/libc/stdio/vfscanf.c	Mon Apr 30 11:14:46 2012	(r234835)
+++ head/lib/libc/stdio/vfscanf.c	Mon Apr 30 11:28:17 2012	(r234836)
@@ -125,7 +125,7 @@ static const mbstate_t initial_mbs;
  */
 
 static __inline int
-convert_char(FILE *fp, char * __restrict p, int width)
+convert_char(FILE *fp, char * p, int width)
 {
 	int n;
 
@@ -151,7 +151,7 @@ convert_char(FILE *fp, char * __restrict
 		return (sum);
 	} else {
 		size_t r = __fread(p, 1, width, fp);
-		
+
 		if (r == 0)
 			return (-1);
 		return (r);
@@ -179,7 +179,7 @@ convert_wchar(FILE *fp, wchar_t *wcp, in
 }
 
 static __inline int
-convert_ccl(FILE *fp, char * __restrict p, int width, const char *ccltab)
+convert_ccl(FILE *fp, char * p, int width, const char *ccltab)
 {
 	char *p0;
 	int n;
@@ -249,7 +249,7 @@ convert_wccl(FILE *fp, wchar_t *wcp, int
 }
 
 static __inline int
-convert_string(FILE *fp, char * __restrict p, int width)
+convert_string(FILE *fp, char * p, int width)
 {
 	char *p0;
 	int n;
@@ -387,7 +387,7 @@ parseint(FILE *fp, char * __restrict buf
 				goto ok;
 			}
 			break;
-					
+
 		/*
 		 * x ok iff flag still set & 2nd char (or 3rd char if
 		 * we have a sign).

Modified: head/lib/libc/stdio/vfwscanf.c
==============================================================================
--- head/lib/libc/stdio/vfwscanf.c	Mon Apr 30 11:14:46 2012	(r234835)
+++ head/lib/libc/stdio/vfwscanf.c	Mon Apr 30 11:28:17 2012	(r234836)
@@ -138,7 +138,7 @@ static const mbstate_t initial_mbs;
  */
 
 static __inline int
-convert_char(FILE *fp, char * __restrict mbp, int width, locale_t locale)
+convert_char(FILE *fp, char * mbp, int width, locale_t locale)
 {
 	mbstate_t mbs;
 	size_t nconv;
@@ -179,7 +179,7 @@ convert_wchar(FILE *fp, wchar_t *wcp, in
 }
 
 static __inline int
-convert_ccl(FILE *fp, char * __restrict mbp, int width, const struct ccl *ccl,
+convert_ccl(FILE *fp, char * mbp, int width, const struct ccl *ccl,
     locale_t locale)
 {
 	mbstate_t mbs;
@@ -237,7 +237,7 @@ convert_wccl(FILE *fp, wchar_t *wcp, int
 }
 
 static __inline int
-convert_string(FILE *fp, char * __restrict mbp, int width, locale_t locale)
+convert_string(FILE *fp, char * mbp, int width, locale_t locale)
 {
 	mbstate_t mbs;
 	size_t nconv;
@@ -372,7 +372,7 @@ parseint(FILE *fp, wchar_t *buf, int wid
 				goto ok;
 			}
 			break;
-					
+
 		/*
 		 * x ok iff flag still set & 2nd char (or 3rd char if
 		 * we have a sign).



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204301128.q3UBSHlb063816>