Anna Zaks | 183ff2a | 2012-06-01 23:48:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -verify %s |
Andy Gibbs | 8e8fb3b | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 2 | // expected-no-diagnostics |
Anna Zaks | 183ff2a | 2012-06-01 23:48:44 +0000 | [diff] [blame] | 3 | |
| 4 | typedef struct { |
| 5 | char I[4]; |
| 6 | int S; |
| 7 | } Hdr; |
| 8 | typedef struct { |
| 9 | short w; |
| 10 | } Hdr2; |
| 11 | typedef struct { |
| 12 | Hdr2 usedtobeundef; |
| 13 | } Info; |
| 14 | typedef struct { |
| 15 | const unsigned char *ib; |
| 16 | int cur; |
| 17 | int end; |
| 18 | } IB; |
Nick Lewycky | cd0655b | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 19 | unsigned long gl(IB *input); |
Anna Zaks | 183ff2a | 2012-06-01 23:48:44 +0000 | [diff] [blame] | 20 | inline void gbs(IB *input, unsigned char *buf, int count); |
| 21 | void getB(IB *st, Hdr2 *usedtobeundef); |
| 22 | inline unsigned char gb(IB *input) { |
| 23 | if (input->cur + 1 > input->end) |
| 24 | ; |
| 25 | return input->ib[(input->cur)++]; |
| 26 | } |
| 27 | static void getID(IB *st, char str[4]) { |
| 28 | str[0] = gb(st); |
| 29 | str[1] = gb(st); |
| 30 | str[2] = gb(st); |
| 31 | str[3] = gb(st); |
| 32 | } |
| 33 | static void getH(IB *st, Hdr *header) { |
| 34 | getID (st, header->I); |
| 35 | header->S = gl(st); |
| 36 | } |
| 37 | static void readILBM(IB *st, Info *pic) { |
| 38 | // Initialize field; |
| 39 | pic->usedtobeundef.w = 5; |
| 40 | |
| 41 | // Time out in the function so that we will be forced to retry with no inlining. |
| 42 | Hdr header; |
| 43 | getH (st, &header); |
| 44 | getID(st, header.I); |
| 45 | int i = 0; |
| 46 | while (st->cur < st->end && i < 4) { |
| 47 | i++; |
| 48 | getH (st, &header); |
| 49 | } |
| 50 | } |
| 51 | int bitmapImageRepFromIFF(IB st, const unsigned char *ib, int il) { |
| 52 | Info pic; |
| 53 | st.ib = ib; |
| 54 | st.cur = 0; |
| 55 | st.end = il; |
| 56 | readILBM(&st,&pic); |
| 57 | return pic.usedtobeundef.w; // No undefined value warning here. |
| 58 | } |