~ubuntu-branches/ubuntu/wily/avr-libc/wily-proposed

« back to all changes in this revision

Viewing changes to tests/simulate/stdlib/strtoul-2.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2009-10-31 11:52:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091031115210-crjd42sn6ezrj52c
Tags: 1:1.6.7-1
* New upstream relese (closes: #544030)
* Added lintian overrides (closes: #553265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Overflow.
2
 
   $Id: strtoul-2.c,v 1.1 2007/02/07 13:42:36 dmix Exp $
3
 
 */
4
 
#include <stdlib.h>
5
 
#include <string.h>
6
 
#include "progmem.h"
7
 
#include "strtoul.h"
8
 
 
9
 
int main ()
10
 
{
11
 
    PROGMEM static struct t_s {
12
 
        char s[14];             /* string to convert    */
13
 
        int base;
14
 
        unsigned long ret;      /* result must  */
15
 
        int err;                /* errno must   */
16
 
        unsigned char len;      /* endptr displacement must     */
17
 
    } t[] = {
18
 
        
19
 
        { "2147483647", 0,      0x7fffffff, 0, 10 },
20
 
        { "0x7fffffff", 0,      0x7fffffff, 0, 10 },
21
 
        { "017777777777", 0,    0x7fffffff, 0, 12 },
22
 
        { "2147483648", 0,      0x80000000, 0, 10 },
23
 
        { "0x80000000", 0,      0x80000000, 0, 10 },
24
 
        { "020000000000", 0,    0x80000000, 0, 12 },
25
 
        
26
 
        { "4294967295", 0,      0xffffffff, 0, 10 },
27
 
        { "4294967296", 0,      0xffffffff, ERANGE, 10 },
28
 
        { "4294967297", 0,      0xffffffff, ERANGE, 10 },
29
 
        { "4294967298", 0,      0xffffffff, ERANGE, 10 },
30
 
        { "4294967299", 0,      0xffffffff, ERANGE, 10 },
31
 
        { "4294967300", 0,      0xffffffff, ERANGE, 10 },
32
 
        { "4294967301", 0,      0xffffffff, ERANGE, 10 },
33
 
        { "4294967302", 0,      0xffffffff, ERANGE, 10 },
34
 
        { "4294967303", 0,      0xffffffff, ERANGE, 10 },
35
 
        { "4294967304", 0,      0xffffffff, ERANGE, 10 },
36
 
        { "4294967305", 0,      0xffffffff, ERANGE, 10 },
37
 
        { "4294967306", 0,      0xffffffff, ERANGE, 10 },
38
 
        { "9999999999999", 0,   0xffffffff, ERANGE, 13 },
39
 
 
40
 
        { "037777777777", 0,    0xffffffff, 0, 12 },
41
 
        { "040000000000", 0,    0xffffffff, ERANGE, 12 },
42
 
        { "040000000001", 0,    0xffffffff, ERANGE, 12 },
43
 
        { "040000000006", 0,    0xffffffff, ERANGE, 12 },
44
 
        { "040000000007", 0,    0xffffffff, ERANGE, 12 },
45
 
        { "040000000010", 0,    0xffffffff, ERANGE, 12 },
46
 
        { "0777777777777", 0,   0xffffffff, ERANGE, 13 },
47
 
        
48
 
        { "0xffffffff", 0,      0xffffffff, 0, 10},
49
 
        { "0x100000000", 0,     0xffffffff, ERANGE, 11 },
50
 
        { "0x100000001", 0,     0xffffffff, ERANGE, 11 },
51
 
        { "0x10000000e", 0,     0xffffffff, ERANGE, 11 },
52
 
        { "0x10000000f", 0,     0xffffffff, ERANGE, 11 },
53
 
        { "0x100000010", 0,     0xffffffff, ERANGE, 11 },
54
 
        { "0xfffffffffff", 0,   0xffffffff, ERANGE, 13 },
55
 
        
56
 
        { "-2147483647", 0,     0x80000001, 0, 11 },
57
 
        { "-0x7fffffff", 0,     0x80000001, 0, 11 },
58
 
        { "-017777777777", 0,   0x80000001, 0, 13 },
59
 
        { "-2147483648", 0,     0x80000000, 0, 11 },
60
 
        { "-0x80000000", 0,     0x80000000, 0, 11 },
61
 
        { "-020000000000", 0,   0x80000000, 0, 13 },
62
 
        { "-2147483649", 0,     0x7fffffff, 0, 11 },
63
 
        { "-0x80000001", 0,     0x7fffffff, 0, 11 },
64
 
        { "-020000000001", 0,   0x7fffffff, 0, 13 },
65
 
        
66
 
        { "-4294967295", 0,     0x00000001, 0, 11 },
67
 
        { "-4294967296", 0,     0xffffffff, ERANGE, 11 },
68
 
        { "-4294967297", 0,     0xffffffff, ERANGE, 11 },
69
 
 
70
 
    };
71
 
    int i;
72
 
    
73
 
    for (i = 0; i != (int)(sizeof(t)/sizeof(t[0])); i++) {
74
 
        struct t_s tt, *p;
75
 
        memcpy_P (&tt, t + i, sizeof(tt));
76
 
        p = &tt;
77
 
        if (t_strtoul (p->s, p->base, p->ret, p->err, p->len))
78
 
            exit (i+1);
79
 
    }
80
 
    return 0;
81
 
}