(root)/
glibc-2.38/
stdio-common/
tst-vfprintf-width-prec-alloc.c
       1  /* Test large width or precision does not involve large allocation.
       2     Copyright (C) 2020-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <stdio.h>
      20  #include <sys/resource.h>
      21  #include <support/check.h>
      22  
      23  char test_string[] = "test";
      24  
      25  static int
      26  do_test (void)
      27  {
      28    struct rlimit limit;
      29    TEST_VERIFY_EXIT (getrlimit (RLIMIT_AS, &limit) == 0);
      30    limit.rlim_cur = 200 * 1024 * 1024;
      31    TEST_VERIFY_EXIT (setrlimit (RLIMIT_AS, &limit) == 0);
      32    FILE *fp = fopen ("/dev/null", "w");
      33    TEST_VERIFY_EXIT (fp != NULL);
      34    TEST_COMPARE (fprintf (fp, "%1000000000d", 1), 1000000000);
      35    TEST_COMPARE (fprintf (fp, "%.1000000000s", test_string), 4);
      36    TEST_COMPARE (fprintf (fp, "%1000000000d %1000000000d", 1, 2), 2000000001);
      37    TEST_COMPARE (fprintf (fp, "%2$.*1$s", 0x7fffffff, test_string), 4);
      38    return 0;
      39  }
      40  
      41  #include <support/test-driver.c>