summaryrefslogtreecommitdiff
path: root/gettext-tools/tests/gettext-8-prg.c
blob: f88062fca5f3698297c3b43bc12e341b95852aff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Test that gettext() does not crash by stack overflow when msgid is very long.
   Copyright (C) 2007, 2015-2016 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

/* Written by Bruno Haible <haible@clisp.cons.org>, 2007.  */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#if HAVE_GETRLIMIT && HAVE_SETRLIMIT
# include <sys/types.h>
# include <sys/time.h>
# include <sys/resource.h>
#endif

/* Make sure we use the included libintl, not the system's one. */
#undef _LIBINTL_H
#include "libgnuintl.h"

int
main ()
{
  size_t n;
  char *msg;
  char *translated;

  n = 1000000;

#if HAVE_GETRLIMIT && HAVE_SETRLIMIT
  {
    struct rlimit limit;

# ifdef RLIMIT_STACK
    if (getrlimit (RLIMIT_STACK, &limit) < 0)
      {
        printf ("Skipping test: getrlimit does not work\n");
        return 77;
      }
    if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > n)
      limit.rlim_max = n;
    limit.rlim_cur = limit.rlim_max;
    if (setrlimit (RLIMIT_STACK, &limit) < 0)
      {
        printf ("Skipping test: setrlimit does not work\n");
        return 77;
      }
# endif
  }
#endif

  msg = (char *) malloc (n + 1);
  if (msg == NULL)
    {
      printf ("Skipping test: out of memory\n");
      return 77;
    }
  memset (msg, 'x', n);
  msg[n] = '\0';

  translated = gettext (msg);
  free (msg);
  assert (translated != NULL);

  return 0;
}