Skip to content

Commit 1f34d82

Browse files
committed
Work around a gcc warning
It seems that annotating sprintf with `write` makes gcc unhappy, as its analyser is unable to understand that we're checking if `__b != -1` before calling `__orig_snprintf`, so let's comment this annotation for now.
1 parent 114b563 commit 1f34d82

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

include/stdio.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ _FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
286286
}
287287

288288
__fh_format(printf, 2, 3)
289-
__fh_access(write_only, 1)
289+
//__fh_access(write_only, 1)
290290
__fh_access(read_only, 2)
291291
_FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
292292
{
@@ -296,13 +296,13 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
296296
__fh_size_t __b = __fh_bos(__s, 0);
297297
int __r;
298298

299-
if (__b != (__fh_size_t)-1) {
300-
__r = __orig_snprintf(__s, __b, __f, __builtin_va_arg_pack());
301-
if (__r != -1 && (__fh_size_t)__r >= __b)
302-
__builtin_trap();
303-
} else {
304-
__r = __orig_sprintf(__s, __f, __builtin_va_arg_pack());
299+
if (__b == (__fh_size_t)-1) {
300+
return __orig_sprintf(__s, __f, __builtin_va_arg_pack());
305301
}
302+
303+
__r = __orig_snprintf(__s, __b, __f, __builtin_va_arg_pack());
304+
if (__r != -1 && (__fh_size_t)__r >= __b)
305+
__builtin_trap();
306306
return __r;
307307
#endif
308308
}

tests/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ RUNTIME_TARGETS= \
9696
test_send_static \
9797
test_sendto_dynamic \
9898
test_sendto_static \
99+
test_sprintf \
100+
test_sprintf_62 \
99101
test_stpcpy_dynamic_write \
100102
test_stpcpy_overwrite_over \
101103
test_stpcpy_overwrite_under \

0 commit comments

Comments
 (0)