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@
This commit is contained in:
parent
7bd5e9b143
commit
671c033623
@ -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 p, int width)
|
||||
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, int width, locale_t locale)
|
||||
}
|
||||
|
||||
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 width, const char *ccltab,
|
||||
}
|
||||
|
||||
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, int width, int base, int flags)
|
||||
goto ok;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
/*
|
||||
* x ok iff flag still set & 2nd char (or 3rd char if
|
||||
* we have a sign).
|
||||
|
@ -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, int width, locale_t locale)
|
||||
}
|
||||
|
||||
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 width, const struct ccl *ccl,
|
||||
}
|
||||
|
||||
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 width, int base, int flags,
|
||||
goto ok;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
/*
|
||||
* x ok iff flag still set & 2nd char (or 3rd char if
|
||||
* we have a sign).
|
||||
|
Loading…
Reference in New Issue
Block a user