Bug Summary

File:backend/dvi/mdvi-lib/paper.c
Warning:line 152, column 17
Access of 'papers' at negative byte offset -24

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 paper.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-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I ../../.. -D PIC -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../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 alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -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/2025-08-13-131048-52863-1 -x c paper.c
1/*
2 * Copyright (C) 2000, Matias Atria
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include <config.h>
20#include <string.h>
21
22#include "common.h"
23#include "mdvi.h"
24#include "private.h"
25
26static const DviPaperSpec papers[] = {
27 {"ISO", 0, 0},
28 {"4A0", "1682mm", "2378mm"},
29 {"2A0", "1189mm", "1682mm"},
30 {"A0", "841mm", "1189mm"},
31 {"A1", "594mm", "841mm"},
32 {"A2", "420mm", "594mm"},
33 {"A3", "297mm", "420mm"},
34 {"A4", "210mm", "297mm"},
35 {"A5", "148mm", "210mm"},
36 {"A6", "105mm", "148mm"},
37 {"A7", "74mm", "105mm"},
38 {"A8", "52mm", "74mm"},
39 {"A9", "37mm", "52mm"},
40 {"A10", "26mm", "37mm"},
41 {"B0", "1000mm", "1414mm"},
42 {"B1", "707mm", "1000mm"},
43 {"B2", "500mm", "707mm"},
44 {"B3", "353mm", "500mm"},
45 {"B4", "250mm", "353mm"},
46 {"B5", "176mm", "250mm"},
47 {"B6", "125mm", "176mm"},
48 {"B7", "88mm", "125mm"},
49 {"B8", "62mm", "88mm"},
50 {"B9", "44mm", "62mm"},
51 {"B10", "31mm", "44mm"},
52 {"C0", "917mm", "1297mm"},
53 {"C1", "648mm", "917mm"},
54 {"C2", "458mm", "648mm"},
55 {"C3", "324mm", "458mm"},
56 {"C4", "229mm", "324mm"},
57 {"C5", "162mm", "229mm"},
58 {"C6", "114mm", "162mm"},
59 {"C7", "81mm", "114mm"},
60 {"C8", "57mm", "81mm"},
61 {"C9", "40mm", "57mm"},
62 {"C10", "28mm", "40mm"},
63 {"US", 0, 0},
64 {"archA", "9in", "12in"},
65 {"archB", "12in", "18in"},
66 {"archC", "18in", "24in"},
67 {"archD", "24in", "36in"},
68 {"archE", "36in", "48in"},
69 {"executive", "7.5in", "10in"},
70 {"flsa", "8.5in", "13in"},
71 {"flse", "8.5in", "13in"},
72 {"halfletter", "5.5in", "8.5in"},
73 {"letter", "8.5in", "11in"},
74 {"legal", "8.5in", "14in"},
75 {"ledger", "17in", "11in"},
76 {"note", "7.5in", "10in"},
77 {"tabloid", "11in", "17in"},
78 {"statement", "5.5in", "8.5in"},
79 {0, 0, 0}
80};
81
82static DviPaperClass str2class(const char *name)
83{
84 if(STRCEQ(name, "ISO")(strcasecmp((name), ("ISO")) == 0))
85 return MDVI_PAPER_CLASS_ISO;
86 else if(STRCEQ(name, "US")(strcasecmp((name), ("US")) == 0))
87 return MDVI_PAPER_CLASS_US;
88 return MDVI_PAPER_CLASS_CUSTOM;
89}
90
91int mdvi_get_paper_size(const char *name, DviPaper *paper)
92{
93 const DviPaperSpec *sp;
94 double a, b;
95 char c, d, e, f;
96 char buf[32];
97
98 paper->pclass = MDVI_PAPER_CLASS_CUSTOM;
99 if(sscanf(name, "%lfx%lf%c%c", &a, &b, &c, &d) == 4) {
100 sprintf(buf, "%12.16f%c%c", a, c, d);
101 paper->inches_wide = unit2pix_factor(buf);
102 sprintf(buf, "%12.16f%c%c", b, c, d);
103 paper->inches_tall = unit2pix_factor(buf);
104 paper->name = _("custom")gettext("custom");
105 return 0;
106 } else if(sscanf(name, "%lf%c%c,%lf%c%c", &a, &c, &d, &b, &e, &f) == 6) {
107 sprintf(buf, "%12.16f%c%c", a, c, d);
108 paper->inches_wide = unit2pix_factor(buf);
109 sprintf(buf, "%12.16f%c%c", b, e, f);
110 paper->inches_tall = unit2pix_factor(buf);
111 paper->name = _("custom")gettext("custom");
112 return 0;
113 }
114
115 for(sp = &papers[0]; sp->name; sp++) {
116 if(!sp->width || !sp->height) {
117 paper->pclass = str2class(sp->name);
118 continue;
119 }
120 if(strcasecmp(sp->name, name) == 0) {
121 paper->inches_wide = unit2pix_factor(sp->width);
122 paper->inches_tall = unit2pix_factor(sp->height);
123 paper->name = sp->name;
124 return 0;
125 }
126 }
127 return -1;
128}
129
130DviPaperSpec *mdvi_get_paper_specs(DviPaperClass pclass)
131{
132 int i;
133 int first, count;
134 DviPaperSpec *spec, *ptr;
135
136 first = -1;
137 count = 0;
138 if(pclass == MDVI_PAPER_CLASS_ANY ||
1
Assuming 'pclass' is not equal to MDVI_PAPER_CLASS_ANY
3
Taking false branch
139 pclass == MDVI_PAPER_CLASS_CUSTOM) {
2
Assuming 'pclass' is not equal to MDVI_PAPER_CLASS_CUSTOM
140 first = 0;
141 count = (sizeof(papers) / sizeof(papers[0])) - 3;
142 } else for(i = 0; papers[i].name; i++) {
4
Loop condition is false. Execution continues on line 151
143 if(papers[i].width == NULL((void*)0)) {
144 if(str2class(papers[i].name) == pclass)
145 first = i;
146 else if(first >= 0)
147 break;
148 } else if(first >= 0)
149 count++;
150 }
151 ptr = spec = xnalloc(DviPaperSpec, count + 1)(DviPaperSpec *)mdvi_calloc((count + 1), sizeof(DviPaperSpec)
)
;
152 for(i = first; papers[i].name&& count > 0; i++) {
5
Access of 'papers' at negative byte offset -24
153 if(papers[i].width) {
154 ptr->name = papers[i].name;
155 ptr->width = papers[i].width;
156 ptr->height = papers[i].height;
157 ptr++;
158 count--;
159 }
160 }
161 ptr->name = NULL((void*)0);
162 ptr->width = NULL((void*)0);
163 ptr->height = NULL((void*)0);
164
165 return spec;
166}
167
168void mdvi_free_paper_specs(DviPaperSpec *spec)
169{
170 mdvi_free(spec);
171}