summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/pr46315.c
blob: 2349284e2e9cf3ddfbf05f3c0490236a2b5299fb (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
/* PR rtl-optimization/46315 */
/* Reported by Magnus Granberg <zorry@gentoo.org> */

/* { dg-do run } */
/* { dg-options "-O2 -fno-strict-overflow" } */

extern void abort (void);

static char const *
parse_ranged (char const *s, int digits)
{
  int n = 0;
  char const *lim = s + digits;
  while (s < lim)
    {
      unsigned d = *s++ - '0';
      if (9 < d)
        return 0;
      n = 10 * n + d;
    }
  return s && 0 <= n && n <= 59 ? s : 0;
}

int main(void)
{
  const char *s = "10092240";

  s = parse_ranged (s, 2);
  s = parse_ranged (s, 2);
  s = parse_ranged (s, 2);
  s = parse_ranged (s, 2);

  if (!s || *s != '\0')
    abort();

  return 0;
}