Bug Summary

File:c:\siege\siege/src/siege/graphics/bitmap.c
Location:line 75, column 12
Description:Branch condition evaluates to a garbage value

Annotated Source Code

1/*
2 * Copyright (c) 2007 SIEGE Development Team
3 * All rights reserved.
4 *
5 * This file is part of libSIEGE.
6 *
7 * This software is copyrighted work licensed under the terms of the
8 * 2-clause BSD license. Please consult the file "COPYING.txt" for
9 * details.
10 *
11 * If you did not recieve the file with this program, please email
12 * Tim Chas <darkuranium@gmail.com>.
13 */
14
15#define SG_BUILD_LIBRARY
16#include <siege/graphics/bitmap.h>
17
18#include <stdlib.h>
19#include <stdio.h>
20
21#include "../internal/stb/stb_image.h"
22
23static int f_read(void* data, char* ptr, int size)
24{
25 SGStream* stream = data;
26 return stream->read(stream->data, ptr, 1, size);
27}
28static void f_skip(void* data, unsigned n)
29{
30 SGStream* stream = data;
31 stream->seek(stream->data, n, SG_SEEK_CUR1);
32}
33static int f_eof(void* data)
34{
35 SGStream* stream = data;
36 return stream->eof(stream->data);
37}
38
39static stbi_io_callbacks imgCallbacks;
40
41SGbool SG_CALL__cdecl _sgBitmapInit(void)
42{
43 imgCallbacks.read = f_read;
44 imgCallbacks.skip = f_skip;
45 imgCallbacks.eof = f_eof;
46 return SG_TRUE1;
47}
48SGbool SG_CALL__cdecl _sgBitmapDeinit(void)
49{
50 return SG_TRUE1;
51}
52
53SGBitmap* SG_CALL__cdecl sgBitmapCreateStream(SGStream* stream, SGbool delstream)
54{
55 SGBitmap* bmp = NULL((void*)0);
56 if(!stream) goto err;
4
Taking false branch
57 bmp = malloc(sizeof(SGBitmap));
5
Uninitialized value stored to field 'deldata'
58 if(!bmp) goto err;
6
Assuming 'bmp' is non-null
7
Taking false branch
59
60
61 // TODO: Load with image BPP
62 int w, h, n;
63 bmp->data = stbi_load_from_callbacks(&imgCallbacks, stream, &w, &h, &n, 4);
64 if(!bmp->data)
8
Taking true branch
65 goto err;
9
Control jumps to line 72
66 bmp->deldata = SG_TRUE1;
67 bmp->width = w;
68 bmp->height = h;
69 bmp->bpp = 32;
70 return bmp;
71err:
72 fprintf(stderr(&_iob[2]), "Could not load image\n");
73 if(bmp)
10
Taking true branch
74 {
75 if(bmp->deldata && bmp->data)
11
Branch condition evaluates to a garbage value
76 free(bmp->data);
77 free(bmp);
78 }
79 return NULL((void*)0);
80}
81SGBitmap* SG_CALL__cdecl sgBitmapCreateFile(const char* fname)
82{
83 SGStream* stream = sgStreamCreateFile(fname, "r");
84 if(!stream)
1
Assuming 'stream' is non-null
2
Taking false branch
85 fprintf(stderr(&_iob[2]), "Could not load image %s\n", fname);
86 return sgBitmapCreateStream(stream, SG_TRUE1);
3
Calling 'sgBitmapCreateStream'
87}
88SGBitmap* SG_CALL__cdecl sgBitmapCreateData(size_t width, size_t height, SGenum bpp, void* data)
89{
90 SGBitmap* bmp = malloc(sizeof(SGBitmap));
91 bmp->width = width;
92 bmp->height = height;
93 bmp->bpp = bpp;
94 bmp->data = data;
95 bmp->deldata = SG_FALSE0;
96
97 return bmp;
98}
99SGBitmap* SG_CALL__cdecl sgBitmapCreate(size_t width, size_t height, SGenum bpp)
100{
101 return sgBitmapCreateData(width, height, bpp, NULL((void*)0));
102}
103void SG_CALL__cdecl sgBitmapDestroy(SGBitmap* bmp)
104{
105 if(!bmp) return;
106
107 if(bmp->deldata)
108 free(bmp->data);
109 free(bmp);
110}
111
112//SGbool SG_CALL sgBitmapConvert(SGBitmap* bmp, SGenum bpp);
113
114//void SG_CALL sgBitmapSetData(SGBitmap* bmp, size_t width, size_t height, SGenum bpp, void* data);
115void SG_CALL__cdecl sgBitmapGetData(SGBitmap* bmp, size_t* width, size_t* height, SGenum* bpp, void** data)
116{
117 if(width) *width = bmp->width;
118 if(height) *height = bmp->height;
119 if(bpp) *bpp = bmp->bpp;
120 if(data) *data = bmp->data;
121}
122
123void SG_CALL__cdecl sgBitmapGetSize(SGBitmap* bmp, size_t* width, size_t* height)
124{
125 if(width) *width = bmp->width;
126 if(height) *height = bmp->height;
127}
128size_t SG_CALL__cdecl sgBitmapGetWidth(SGBitmap* bmp)
129{
130 return bmp->width;
131}
132size_t SG_CALL__cdecl sgBitmapGetHeight(SGBitmap* bmp)
133{
134 return bmp->height;
135}
136
137SGenum SG_CALL__cdecl sgBitmapGetBPP(SGBitmap* bmp)
138{
139 return bmp->bpp;
140}