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