Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9bed827

Browse files
committed
Fix configure's snprintf test so it exposes HP-UX bug.
Since commite1d19c9, buildfarm member gharial has been failing withsymptoms indicating that snprintf sometimes returns -1 for bufferoverrun, even though it passes the added configure check. Somegoogle research suggests that this happens only in limited cases,such as when the overrun happens partway through a %d item. Adjustthe configure check to exercise it that way. Since I'm now feelingmore paranoid than I was before, also make the test explicitly verifythat the buffer doesn't get physically overrun.
1 parentb94f7b5 commit9bed827

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

‎config/c-library.m4

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ AC_MSG_RESULT([$pgac_cv_snprintf_arg_control])
202202
])# PGAC_FUNC_SNPRINTF_ARG_CONTROL
203203

204204
# PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
205-
# ---------------------------------------
205+
# ---------------------------------
206206
# Determine if snprintf supports the z length modifier for printing
207207
# size_t-sized variables. That's supported by C99 and POSIX but not
208208
# all platforms play ball, so we must test whether it's working.
@@ -243,9 +243,11 @@ AC_MSG_RESULT([$pgac_cv_snprintf_size_t_support])
243243
# Determine whether snprintf returns the desired buffer length when
244244
# it overruns the actual buffer length. That's required by C99 and POSIX
245245
# but ancient platforms don't behave that way, so we must test.
246+
# While we're at it, let's just verify that it doesn't physically overrun
247+
# the buffer.
246248
#
247249
AC_DEFUN([PGAC_FUNC_SNPRINTF_C99_RESULT],
248-
[AC_MSG_CHECKING([whether snprintfreports buffer overrun per C99])
250+
[AC_MSG_CHECKING([whether snprintfhandles buffer overrun per C99])
249251
AC_CACHE_VAL(pgac_cv_snprintf_c99_result,
250252
[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
251253
#include <string.h>
@@ -254,7 +256,10 @@ int main()
254256
{
255257
char buf[10];
256258
257-
if (snprintf(buf, sizeof(buf), "12345678901234567890") != 20)
259+
strcpy(buf, "abcdefghi");
260+
if (snprintf(buf, 4, "%d", 123456) != 6)
261+
return 1;
262+
if (strcmp(buf, "123") != 0 || buf[4] != 'e')
258263
return 1;
259264
return 0;
260265
}]])],

‎configure

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16378,8 +16378,8 @@ fi
1637816378
# Force use of our snprintf if the system's doesn't handle buffer overrun
1637916379
# as specified by C99.
1638016380
if test "$pgac_need_repl_snprintf" = no; then
16381-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether snprintfreports buffer overrun per C99" >&5
16382-
$as_echo_n "checking whether snprintfreports buffer overrun per C99... " >&6; }
16381+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether snprintfhandles buffer overrun per C99" >&5
16382+
$as_echo_n "checking whether snprintfhandles buffer overrun per C99... " >&6; }
1638316383
if ${pgac_cv_snprintf_c99_result+:} false; then :
1638416384
$as_echo_n "(cached) " >&6
1638516385
else
@@ -16395,7 +16395,10 @@ int main()
1639516395
{
1639616396
char buf[10];
1639716397

16398-
if (snprintf(buf, sizeof(buf), "12345678901234567890") != 20)
16398+
strcpy(buf, "abcdefghi");
16399+
if (snprintf(buf, 4, "%d", 123456) != 6)
16400+
return 1;
16401+
if (strcmp(buf, "123") != 0 || buf[4] != 'e')
1639916402
return 1;
1640016403
return 0;
1640116404
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp