Bug Summary

File:backend/dvi/mdvi-lib/gf.c
Warning:line 301, column 29
This statement is never executed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name gf.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/backend/dvi/mdvi-lib -fcoverage-compilation-dir=/rootdir/backend/dvi/mdvi-lib -resource-dir /usr/lib/llvm-21/lib/clang/21 -D HAVE_CONFIG_H -I . -I ../../.. -D PIC -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/15/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-checker deadcode.DeadStores -analyzer-checker security.ArrayBound -analyzer-checker unix.cstring.NotNullTerminated -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2026-04-13-165734-53075-1 -x c gf.c
1/* gf.c - GF font support */
2/*
3 * Copyright (C) 2000, Matias Atria
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20/* functions to read GF fonts */
21
22#include <config.h>
23#include <string.h>
24#include "common.h"
25#include "mdvi.h"
26#include "private.h"
27
28/* opcodes */
29
30#define GF_PAINT00 0
31#define GF_PAINT164 64
32#define GF_PAINT265 65
33#define GF_PAINT366 66
34#define GF_BOC67 67
35#define GF_BOC168 68
36#define GF_EOC69 69
37#define GF_SKIP070 70
38#define GF_SKIP171 71
39#define GF_SKIP272 72
40#define GF_SKIP373 73
41#define GF_NEW_ROW_074 74
42#define GF_NEW_ROW_175 75
43#define GF_NEW_ROW_MAX238 238
44#define GF_XXX1239 239
45#define GF_XXX2240 240
46#define GF_XXX3241 241
47#define GF_XXX4242 242
48#define GF_YYY243 243
49#define GF_NOOP244 244
50#define GF_LOC245 245
51#define GF_LOC0246 246
52#define GF_PRE247 247
53#define GF_POST248 248
54#define GF_POST_POST249 249
55
56#define GF_ID131 131
57#define GF_TRAILER223 223
58
59#define BLACK1 1
60#define WHITE0 0
61
62static int gf_load_font __PROTO((DviParams *, DviFont *))(DviParams *, DviFont *);
63static int gf_font_get_glyph __PROTO((DviParams *, DviFont *, int))(DviParams *, DviFont *, int);
64
65/* only symbol exported by this file */
66DviFontInfo gf_font_info = {
67 "GF",
68 0, /* scaling not supported natively */
69 gf_load_font,
70 gf_font_get_glyph,
71 mdvi_shrink_glyph,
72 mdvi_shrink_glyph_grey,
73 NULL((void*)0), /* free */
74 NULL((void*)0), /* reset */
75 NULL((void*)0), /* lookup */
76 kpse_gf_format,
77 NULL((void*)0)
78};
79
80static int gf_read_bitmap(FILE *p, DviFontChar *ch)
81{
82 int op;
83 int min_n, max_n;
84 int min_m, max_m;
85 int paint_switch;
86 int x, y;
87 int bpl;
88 Int32 par;
89 BmUnit *line;
90 BITMAP *map;
91
92 fseek(p, (long)ch->offset, SEEK_SET0);
93 op = fuget1(p)((unsigned)getc(p));
94 if(op == GF_BOC67) {
95 /* skip character code */
96 fuget4(p)fugetn((p), 4);
97 /* skip pointer */
98 fuget4(p)fugetn((p), 4);
99 min_m = fsget4(p)fsgetn((p), 4);
100 max_m = fsget4(p)fsgetn((p), 4);
101 min_n = fsget4(p)fsgetn((p), 4);
102 max_n = fsget4(p)fsgetn((p), 4);
103 } else if(op == GF_BOC168) {
104 /* skip character code */
105 fuget1(p)((unsigned)getc(p));
106 min_m = fuget1(p)((unsigned)getc(p)); /* this is max_m - min_m */
107 max_m = fuget1(p)((unsigned)getc(p));
108 min_n = fuget1(p)((unsigned)getc(p)); /* this is max_n - min_n */
109 max_n = fuget1(p)((unsigned)getc(p));
110 min_m = max_m - min_m;
111 min_n = max_n - min_n;
112 } else {
113 mdvi_error(_("GF: invalid opcode %d in character %d\n")gettext("GF: invalid opcode %d in character %d\n"),
114 op, ch->code);
115 return -1;
116 }
117
118 ch->x = -min_m;
119 ch->y = max_n;
120 ch->width = max_m - min_m + 1;
121 ch->height = max_n - min_n + 1;
122 map = bitmap_alloc(ch->width, ch->height);
123
124 ch->glyph.data = map;
125 ch->glyph.x = ch->x;
126 ch->glyph.y = ch->y;
127 ch->glyph.w = ch->width;
128 ch->glyph.h = ch->height;
129
130#define COLOR(x)((x) ? "BLACK" : "WHITE") ((x) ? "BLACK" : "WHITE")
131
132 paint_switch = WHITE0;
133 x = y = 0;
134 line = map->data;
135 bpl = map->stride;
136 DEBUG((DBG_BITMAPS, "(gf) reading character %d\n", ch->code))__debug ((1 << 8), "(gf) reading character %d\n", ch->
code)
;
137 while((op = fuget1(p)((unsigned)getc(p))) != GF_EOC69) {
138 Int32 n;
139
140 if(feof(p))
141 break;
142 if(op == GF_PAINT00) {
143 DEBUG((DBG_BITMAPS, "(gf) Paint0 %s -> %s\n",__debug ((1 << 8), "(gf) Paint0 %s -> %s\n", ((paint_switch
) ? "BLACK" : "WHITE"), ((!paint_switch) ? "BLACK" : "WHITE")
)
144 COLOR(paint_switch), COLOR(!paint_switch)))__debug ((1 << 8), "(gf) Paint0 %s -> %s\n", ((paint_switch
) ? "BLACK" : "WHITE"), ((!paint_switch) ? "BLACK" : "WHITE")
)
;
145 paint_switch = !paint_switch;
146 } else if(op <= GF_PAINT366) {
147 if(op < GF_PAINT164)
148 par = op;
149 else
150 par = fugetn(p, op - GF_PAINT164 + 1);
151 if(y >= ch->height || x + par >= ch->width)
152 goto toobig;
153 /* paint everything between columns x and x + par - 1 */
154 DEBUG((DBG_BITMAPS, "(gf) Paint %d %s from (%d,%d)\n",__debug ((1 << 8), "(gf) Paint %d %s from (%d,%d)\n", par
, ((paint_switch) ? "BLACK" : "WHITE"), x, y)
155 par, COLOR(paint_switch), x, y))__debug ((1 << 8), "(gf) Paint %d %s from (%d,%d)\n", par
, ((paint_switch) ? "BLACK" : "WHITE"), x, y)
;
156 if(paint_switch == BLACK1)
157 bitmap_paint_bits(line + (x / BITMAP_BITS(4 << 3)),
158 x % BITMAP_BITS(4 << 3), par);
159 paint_switch = !paint_switch;
160 x += par;
161 } else if(op >= GF_NEW_ROW_074 && op <= GF_NEW_ROW_MAX238) {
162 y++;
163 line = bm_offset(line, bpl)(BmUnit *)((Uchar *)(line) + (bpl));
164 x = op - GF_NEW_ROW_074;
165 paint_switch = BLACK1;
166 DEBUG((DBG_BITMAPS, "(gf) new_row_%d\n", x))__debug ((1 << 8), "(gf) new_row_%d\n", x);
167 } else switch(op) {
168 case GF_SKIP070:
169 y++;
170 line = bm_offset(line, bpl)(BmUnit *)((Uchar *)(line) + (bpl));
171 x = 0;
172 paint_switch = WHITE0;
173 DEBUG((DBG_BITMAPS, "(gf) skip_0\n"))__debug ((1 << 8), "(gf) skip_0\n");
174 break;
175 case GF_SKIP171:
176 case GF_SKIP272:
177 case GF_SKIP373:
178 par = fugetn(p, op - GF_SKIP171 + 1);
179 y += par + 1;
180 line = bm_offset(line, (par + 1) * bpl)(BmUnit *)((Uchar *)(line) + ((par + 1) * bpl));
181 x = 0;
182 paint_switch = WHITE0;
183 DEBUG((DBG_BITMAPS, "(gf) skip_%d\n", op - GF_SKIP1))__debug ((1 << 8), "(gf) skip_%d\n", op - 71);
184 break;
185 case GF_XXX1239:
186 case GF_XXX2240:
187 case GF_XXX3241:
188 case GF_XXX4242: {
189#ifndef NODEBUG
190 char *s;
191
192 s = read_string(p, op - GF_XXX1239 + 1, NULL((void*)0), 0);
193 DEBUG((DBG_SPECIAL, "(gf) Character %d: Special \"%s\"\n",__debug ((1 << 5), "(gf) Character %d: Special \"%s\"\n"
, ch->code, s)
194 ch->code, s))__debug ((1 << 5), "(gf) Character %d: Special \"%s\"\n"
, ch->code, s)
;
195 mdvi_free(s);
196#else
197 n = fugetn(p, op - GF_XXX1239 + 1);
198 fseek(p, (long)n, SEEK_CUR1);
199#endif
200 break;
201 }
202 case GF_YYY243:
203 n = fuget4(p)fugetn((p), 4);
204 DEBUG((DBG_SPECIAL, "(gf) Character %d: MF special %u\n",__debug ((1 << 5), "(gf) Character %d: MF special %u\n"
, ch->code, n)
205 ch->code, n))__debug ((1 << 5), "(gf) Character %d: MF special %u\n"
, ch->code, n)
;
206 break;
207 case GF_NOOP244:
208 DEBUG((DBG_BITMAPS, "(gf) no_op\n"))__debug ((1 << 8), "(gf) no_op\n");
209 break;
210 default:
211 mdvi_error(_("(gf) Character %d: invalid opcode %d\n")gettext("(gf) Character %d: invalid opcode %d\n"),
212 ch->code, op);
213 goto error;
214 }
215 /* chech that we're still inside the bitmap */
216 if(x > ch->width || y > ch->height)
217 goto toobig;
218 DEBUG((DBG_BITMAPS, "(gf) curr_loc @ (%d,%d)\n", x, y))__debug ((1 << 8), "(gf) curr_loc @ (%d,%d)\n", x, y);
219 }
220
221 if(op != GF_EOC69)
222 goto error;
223 DEBUG((DBG_BITMAPS, "(gf) end of character %d\n", ch->code))__debug ((1 << 8), "(gf) end of character %d\n", ch->
code)
;
224 return 0;
225
226toobig:
227 mdvi_error(_("(gf) character %d has an incorrect bounding box\n")gettext("(gf) character %d has an incorrect bounding box\n"),
228 ch->code);
229error:
230 bitmap_destroy(map);
231 ch->glyph.data = NULL((void*)0);
232 return -1;
233}
234
235static int
236gf_load_font (DviParams *unused GNUC_UNUSED__attribute__ ((__unused__)),
237 DviFont *font)
238{
239 int i;
240 int n;
241 int loc;
242 int hic;
243 FILE *p;
244 Int32 word;
245 int op;
246 long alpha, beta, z;
247#ifndef NODEBUG
248 char s[256];
249#endif
250
251 p = font->in;
252
253 /* check preamble */
254 loc = fuget1(p)((unsigned)getc(p)); hic = fuget1(p)((unsigned)getc(p));
255 if(loc != GF_PRE247 || hic != GF_ID131)
256 goto badgf;
257 loc = fuget1(p)((unsigned)getc(p));
258#ifndef NODEBUG
259 for(i = 0; i < loc; i++)
260 s[i] = fuget1(p)((unsigned)getc(p));
261 s[i] = 0;
262 DEBUG((DBG_FONTS, "(gf) %s: %s\n", font->fontname, s))__debug ((1 << 1), "(gf) %s: %s\n", font->fontname, s
)
;
263#else
264 fseek(p, (long)loc, SEEK_CUR1);
265#endif
266 /* now read character locators in postamble */
267 if(fseek(p, (long)-1, SEEK_END2) == -1)
268 return -1;
269
270 n = 0;
271 while((op = fuget1(p)((unsigned)getc(p))) == GF_TRAILER223) {
272 if(fseek(p, (long)-2, SEEK_CUR1) < 0)
273 break;
274 n++;
275 }
276 if(op != GF_ID131 || n < 4)
277 goto badgf;
278 /* get the pointer to the postamble */
279 fseek(p, (long)-5, SEEK_CUR1);
280 op = fuget4(p)fugetn((p), 4);
281 /* jump to it */
282 fseek(p, (long)op, SEEK_SET0);
283 if(fuget1(p)((unsigned)getc(p)) != GF_POST248)
284 goto badgf;
285 /* skip pointer to last EOC */
286 fuget4(p)fugetn((p), 4);
287 /* get the design size */
288 font->design = fuget4(p)fugetn((p), 4);
289 /* the checksum */
290 word = fuget4(p)fugetn((p), 4);
291 if(word && font->checksum && font->checksum != word) {
292 mdvi_warning(_("%s: bad checksum (expected %u, found %u)\n")gettext("%s: bad checksum (expected %u, found %u)\n"),
293 font->fontname, font->checksum, word);
294 } else if(!font->checksum)
295 font->checksum = word;
296 /* skip pixels per point ratio */
297 fuget4(p)fugetn((p), 4);
298 fuget4(p)fugetn((p), 4);
299 font->chars = xnalloc(DviFontChar, 256)(DviFontChar *)mdvi_calloc((256), sizeof(DviFontChar));
300 for(loc = 0; loc < 256; loc++)
301 font->chars[loc].offset = 0;
This statement is never executed
302 /* skip glyph "bounding box" */
303 fseek(p, (long)16, SEEK_CUR1);
304 loc = 256;
305 hic = -1;
306 TFMPREPARE(font->scale, z, alpha, beta)do { alpha = 16; z = (font->scale); while(z > 040000000L
) { z >>= 1; alpha <<= 1; } beta = 256 / alpha; alpha
*= z; } while(0)
;
307 while((op = fuget1(p)((unsigned)getc(p))) != GF_POST_POST249) {
308 DviFontChar *ch;
309 int cc;
310
311 /* get the character code */
312 cc = fuget1(p)((unsigned)getc(p));
313 if(cc < loc)
314 loc = cc;
315 if(cc > hic)
316 hic = cc;
317 ch = &font->chars[cc];
318 switch(op) {
319 case GF_LOC245:
320 fsget4(p)fsgetn((p), 4); /* skip dx */
321 fsget4(p)fsgetn((p), 4); /* skip dy */
322 break;
323 case GF_LOC0246:
324 fuget1(p)((unsigned)getc(p)); /* skip dx */
325 /* dy assumed 0 */
326 break;
327 default:
328 mdvi_error(_("%s: junk in postamble\n")gettext("%s: junk in postamble\n"), font->fontname);
329 goto error;
330 }
331 ch->code = cc;
332 ch->tfmwidth = fuget4(p)fugetn((p), 4);
333 ch->tfmwidth = TFMSCALE(ch->tfmwidth, z, alpha, beta)(((((z) >> 24) & 0xff) == 255) ? ((((((((z)) & 0xff
) * ((ch->tfmwidth))) >> 8) + (((((z)) >> 8) &
0xff) * ((ch->tfmwidth)))) >> 8) + ((((z)) >>
16) & 0xff) * ((ch->tfmwidth))) / (beta) - (alpha) : (
(((((((z)) & 0xff) * ((ch->tfmwidth))) >> 8) + (
((((z)) >> 8) & 0xff) * ((ch->tfmwidth)))) >>
8) + ((((z)) >> 16) & 0xff) * ((ch->tfmwidth)))
/ (beta))
;
334 ch->offset = fuget4(p)fugetn((p), 4);
335 if(ch->offset == -1)
336 ch->offset = 0;
337 /* initialize the rest of the glyph information */
338 ch->x = 0;
339 ch->y = 0;
340 ch->width = 0;
341 ch->height = 0;
342 ch->glyph.data = NULL((void*)0);
343 ch->shrunk.data = NULL((void*)0);
344 ch->grey.data = NULL((void*)0);
345 ch->flags = 0;
346 ch->loaded = 0;
347 }
348
349 if(op != GF_POST_POST249)
350 goto badgf;
351
352 if(loc > 0 || hic < 255) {
353 /* shrink to optimal size */
354 memmove(font->chars, font->chars + loc,
355 (hic - loc + 1) * sizeof(DviFontChar));
356 font->chars = xresize(font->chars,(DviFontChar *)mdvi_realloc((font->chars), (hic - loc + 1)
* sizeof(DviFontChar))
357 DviFontChar, hic - loc + 1)(DviFontChar *)mdvi_realloc((font->chars), (hic - loc + 1)
* sizeof(DviFontChar))
;
358 }
359 font->loc = loc;
360 font->hic = hic;
361
362 return 0;
363
364badgf:
365 mdvi_error(_("%s: File corrupted, or not a GF file\n")gettext("%s: File corrupted, or not a GF file\n"), font->fontname);
366error:
367 if(font->chars) {
368 mdvi_free(font->chars);
369 font->chars = NULL((void*)0);
370 }
371 font->loc = font->hic = 0;
372 return -1;
373}
374
375static int
376gf_font_get_glyph (DviParams *params GNUC_UNUSED__attribute__ ((__unused__)),
377 DviFont *font,
378 int code)
379{
380 DviFontChar *ch;
381
382 if(code < font->loc || code > font->hic || !font->chars)
383 return -1;
384 ch = &font->chars[code - font->loc];
385
386 if(!ch->loaded) {
387 if(ch->offset == 0)
388 return -1;
389 DEBUG((DBG_GLYPHS, "(gf) %s: loading GF glyph for character %d\n",__debug ((1 << 7), "(gf) %s: loading GF glyph for character %d\n"
, font->fontname, code)
390 font->fontname, code))__debug ((1 << 7), "(gf) %s: loading GF glyph for character %d\n"
, font->fontname, code)
;
391 if(font->in == NULL((void*)0) && font_reopen(font) < 0)
392 return -1;
393 if(fseek(font->in, ch->offset, SEEK_SET0) == -1)
394 return -1;
395 if(gf_read_bitmap(font->in, ch) < 0)
396 return -1;
397 ch->loaded = 1;
398 }
399 return 0;
400}