Bug Summary

File:src/usr.bin/bc/obj/bc.c
Warning:line 814, column 10
Passed-by-value struct argument contains uninitialized data (e.g., field: 'data')

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name bc.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 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.bin/bc/obj -resource-dir /usr/local/llvm16/lib/clang/16 -I . -I /usr/src/usr.bin/bc -internal-isystem /usr/local/llvm16/lib/clang/16/include -internal-externc-isystem /usr/include -O2 -Wno-unused -fdebug-compilation-dir=/usr/src/usr.bin/bc/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fcf-protection=branch -fno-jump-tables -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/scan/2024-01-11-140451-98009-1 -x c bc.c
1#include <stdlib.h>
2#include <string.h>
3#define YYBYACC1 1
4#define YYMAJOR1 1
5#define YYMINOR9 9
6#define YYLEXyylex() yylex()
7#define YYEMPTY-1 -1
8#define yyclearin(yychar=(-1)) (yychar=(YYEMPTY-1))
9#define yyerrok(yyerrflag=0) (yyerrflag=0)
10#define YYRECOVERING()(yyerrflag!=0) (yyerrflag!=0)
11#define YYPREFIX"yy" "yy"
12#line 2 "/usr/src/usr.bin/bc/bc.y"
13/* $OpenBSD: bc.y,v 1.53 2023/03/08 04:43:10 guenther Exp $ */
14
15/*
16 * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
17 *
18 * Permission to use, copy, modify, and distribute this software for any
19 * purpose with or without fee is hereby granted, provided that the above
20 * copyright notice and this permission notice appear in all copies.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
23 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
25 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
27 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
28 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 */
30
31/*
32 * This implementation of bc(1) uses concepts from the original 4.4
33 * BSD bc(1). The code itself is a complete rewrite, based on the
34 * Posix defined bc(1) grammar. Other differences include type safe
35 * usage of pointers to build the tree of emitted code, typed yacc
36 * rule values, dynamic allocation of all data structures and a
37 * completely rewritten lexical analyzer using lex(1).
38 *
39 * Some effort has been made to make sure that the generated code is
40 * the same as the code generated by the older version, to provide
41 * easy regression testing.
42 */
43
44#include <sys/types.h>
45#include <sys/wait.h>
46
47#include <ctype.h>
48#include <err.h>
49#include <errno(*__errno()).h>
50#include <histedit.h>
51#include <limits.h>
52#include <search.h>
53#include <signal.h>
54#include <stdarg.h>
55#include <string.h>
56#include <unistd.h>
57
58#include "extern.h"
59#include "pathnames.h"
60
61#define END_NODE((ssize_t) -1) ((ssize_t) -1)
62#define CONST_STRING((ssize_t) -2) ((ssize_t) -2)
63#define ALLOC_STRING((ssize_t) -3) ((ssize_t) -3)
64
65struct tree {
66 ssize_t index;
67 union {
68 char *astr;
69 const char *cstr;
70 } u;
71};
72
73int yyparse(void);
74int yywrap(void);
75
76int fileindex;
77int sargc;
78char **sargv;
79char *filename;
80char *cmdexpr;
81
82static void grow(void);
83static ssize_t cs(const char *);
84static ssize_t as(const char *);
85static ssize_t node(ssize_t, ...);
86static void emit(ssize_t, int);
87static void emit_macro(int, ssize_t);
88static void free_tree(void);
89static ssize_t numnode(int);
90static ssize_t lookup(char *, size_t, char);
91static ssize_t letter_node(char *);
92static ssize_t array_node(char *);
93static ssize_t function_node(char *);
94
95static void add_par(ssize_t);
96static void add_local(ssize_t);
97static void warning(const char *);
98static void init(void);
99static __dead__attribute__((__noreturn__)) void usage(void);
100static char *escape(const char *);
101
102static ssize_t instr_sz = 0;
103static struct tree *instructions = NULL((void *)0);
104static ssize_t current = 0;
105static int macro_char = '0';
106static int reset_macro_char = '0';
107static int nesting = 0;
108static int breakstack[16];
109static int breaksp = 0;
110static ssize_t prologue;
111static ssize_t epilogue;
112static bool_Bool st_has_continue;
113static char str_table[UCHAR_MAX0xff][2];
114static bool_Bool do_fork = true1;
115static u_short var_count;
116static pid_t dc;
117
118extern char *__progname;
119
120#define BREAKSTACK_SZ(sizeof(breakstack)/sizeof(breakstack[0])) (sizeof(breakstack)/sizeof(breakstack[0]))
121
122/* These values are 4.4BSD bc compatible */
123#define FUNC_CHAR0x01 0x01
124#define ARRAY_CHAR0xa1 0xa1
125
126/* Skip '\0', [, \ and ] */
127#define ENCODE(c)((c) < '[' ? (c) : (c) + 3); ((c) < '[' ? (c) : (c) + 3);
128#define VAR_BASE(256-4) (256-4)
129#define MAX_VARIABLES((256-4) * (256-4)) (VAR_BASE(256-4) * VAR_BASE(256-4))
130
131#line 124 "/usr/src/usr.bin/bc/bc.y"
132#ifndef YYSTYPE_DEFINED
133#define YYSTYPE_DEFINED
134typedef union {
135 ssize_t node;
136 struct lvalue lvalue;
137 const char *str;
138 char *astr;
139} YYSTYPE;
140#endif /* YYSTYPE_DEFINED */
141#line 142 "bc.c"
142#define COMMA257 257
143#define SEMICOLON258 258
144#define LPAR259 259
145#define RPAR260 260
146#define LBRACE261 261
147#define RBRACE262 262
148#define LBRACKET263 263
149#define RBRACKET264 264
150#define DOT265 265
151#define NEWLINE266 266
152#define LETTER267 267
153#define NUMBER268 268
154#define STRING269 269
155#define DEFINE270 270
156#define BREAK271 271
157#define QUIT272 272
158#define LENGTH273 273
159#define RETURN274 274
160#define FOR275 275
161#define IF276 276
162#define WHILE277 277
163#define SQRT278 278
164#define SCALE279 279
165#define IBASE280 280
166#define OBASE281 281
167#define AUTO282 282
168#define CONTINUE283 283
169#define ELSE284 284
170#define PRINT285 285
171#define BOOL_OR286 286
172#define BOOL_AND287 287
173#define BOOL_NOT288 288
174#define EQUALS289 289
175#define LESS_EQ290 290
176#define GREATER_EQ291 291
177#define UNEQUALS292 292
178#define LESS293 293
179#define GREATER294 294
180#define ASSIGN_OP295 295
181#define PLUS296 296
182#define MINUS297 297
183#define MULTIPLY298 298
184#define DIVIDE299 299
185#define REMAINDER300 300
186#define EXPONENT301 301
187#define UMINUS302 302
188#define INCR303 303
189#define DECR304 304
190#define YYERRCODE256 256
191const short yylhs[] =
192 { -1,
193 0, 0, 7, 7, 7, 7, 16, 16, 16, 16,
194 18, 18, 18, 18, 18, 18, 11, 11, 17, 17,
195 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
196 17, 3, 19, 5, 6, 21, 21, 20, 20, 23,
197 23, 23, 23, 22, 22, 22, 24, 24, 24, 24,
198 8, 8, 2, 2, 2, 10, 10, 14, 14, 14,
199 14, 14, 14, 14, 15, 15, 15, 9, 9, 4,
200 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
201 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
202 4, 4, 4, 4, 4, 4, 4, 4, 1, 1,
203 1, 1, 1, 13, 13, 12, 12,
204};
205const short yylen[] =
206 { 2,
207 0, 2, 2, 1, 2, 2, 0, 1, 3, 2,
208 0, 1, 2, 3, 2, 3, 0, 1, 1, 3,
209 1, 1, 1, 1, 2, 11, 7, 11, 7, 3,
210 2, 0, 0, 9, 3, 0, 1, 0, 1, 1,
211 3, 3, 5, 0, 3, 3, 1, 3, 3, 5,
212 0, 1, 1, 3, 5, 0, 1, 3, 3, 3,
213 3, 3, 3, 1, 0, 1, 2, 0, 1, 1,
214 1, 1, 3, 4, 2, 3, 3, 3, 3, 3,
215 3, 2, 2, 2, 2, 3, 4, 4, 4, 2,
216 5, 5, 3, 3, 3, 3, 3, 3, 1, 4,
217 1, 1, 1, 1, 3, 1, 1,
218};
219const short yydefred[] =
220 { 1,
221 0, 0, 0, 0, 71, 0, 72, 21, 0, 22,
222 24, 0, 0, 0, 0, 0, 0, 0, 102, 103,
223 23, 0, 0, 0, 0, 0, 0, 0, 4, 0,
224 2, 0, 8, 5, 6, 0, 0, 12, 0, 0,
225 0, 0, 0, 0, 0, 25, 32, 32, 32, 0,
226 0, 107, 0, 104, 0, 0, 75, 0, 101, 82,
227 83, 0, 84, 85, 32, 32, 0, 0, 0, 0,
228 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
229 0, 0, 3, 0, 73, 0, 30, 0, 0, 0,
230 0, 0, 35, 0, 67, 0, 33, 0, 0, 0,
231 0, 0, 33, 33, 0, 0, 0, 0, 0, 0,
232 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
233 0, 16, 14, 0, 74, 100, 87, 0, 0, 0,
234 0, 0, 88, 89, 105, 0, 0, 41, 37, 0,
235 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
236 0, 0, 0, 0, 0, 0, 0, 0, 57, 0,
237 0, 0, 0, 0, 0, 0, 33, 18, 0, 43,
238 55, 0, 0, 29, 0, 0, 0, 32, 0, 0,
239 0, 0, 33, 0, 0, 46, 45, 34, 33, 0,
240 48, 0, 26, 28, 0, 50,
241};
242const short yydgoto[] =
243 { 1,
244 36, 89, 96, 28, 29, 30, 31, 91, 129, 158,
245 167, 54, 55, 132, 46, 32, 168, 39, 130, 80,
246 140, 176, 81, 180,
247};
248const short yysindex[] =
249 { 0,
250 -77, -188, 196, 88, 0, -257, 0, 0, -260, 0,
251 0, -236, 223, -225, -109, -107, -103, -102, 0, 0,
252 0, 115, 196, 196, -227, -227, -291, -17, 0, -237,
253 0, -202, 0, 0, 0, -166, 479, 0, -89, 196,
254 196, -87, 196, 142, -17, 0, 0, 0, 0, 196,
255 196, 0, -17, 0, -195, 815, 0, -170, 0, 0,
256 0, 196, 0, 0, 0, 0, 196, 196, 196, 196,
257 196, 196, 196, 196, 196, 196, 196, 196, -85, -157,
258 -81, 88, 0, 196, 0, 88, 0, 88, -72, -17,
259 -73, 607, 0, 496, 0, 196, 0, 196, 514, 531,
260 115, 291, 0, 0, 291, 291, 291, 291, 291, 291,
261 126, 126, -71, -71, -71, -71, -33, -37, -32, 0,
262 291, 0, 0, 250, 0, 0, 0, -17, -21, 196,
263 787, -20, 0, 0, 0, 196, 196, 0, 0, -7,
264 -6, -216, -17, 196, 6, 196, 196, 196, 196, 196,
265 196, 88, 802, 815, -4, 7, 169, 20, 0, 88,
266 291, 291, 291, 291, 291, 291, 0, 0, 21, 0,
267 0, 196, 5, 0, 41, 88, 51, 0, 49, -207,
268 -45, 88, 0, 54, 65, 0, 0, 0, 0, 88,
269 0, 74, 0, 0, 76, 0,};
270const short yyrindex[] =
271 { 0,
272 -175, 0, 0, -43, 0, -48, 0, 0, 0, 0,
273 0, 0, 2, 0, 0, 0, 0, 1, 0, 0,
274 0, 0, 0, 0, 0, 0, 461, 221, 0, 81,
275 0, 0, 0, 0, 0, 275, 0, 0, 0, 82,
276 0, 0, 0, 0, 384, 0, 0, 0, 0, 0,
277 0, 0, 286, 0, 445, -229, 0, 320, 0, 0,
278 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
279 0, 0, 0, 0, 0, 0, 0, 0, -152, 0,
280 84, -133, 0, 0, 0, -34, 0, 72, 86, -86,
281 0, 0, 0, 0, 0, 90, 0, 0, 0, 0,
282 0, -126, 0, 0, 194, 663, 694, 704, 735, 745,
283 576, 590, 339, 383, 400, 444, 0, 89, 0, 0,
284 652, 0, 0, 0, 0, 0, 0, -197, 0, 0,
285 -117, 0, 0, 0, 0, 0, 0, 0, 0, 0,
286 -74, -180, -35, 96, 0, 0, 0, 0, 0, 0,
287 0, 577, 786, 776, 0, 0, 0, 0, 0, 577,
288 -241, -160, -156, -53, 112, 119, 0, 0, 48, 0,
289 0, 98, 77, 0, 0, -43, 0, 0, -169, 0,
290 0, 577, 0, 0, 0, 0, 0, 0, 0, 577,
291 0, -104, 0, 0, 0, 0,};
292const short yygindex[] =
293 { 0,
294 -1, 0, -39, -2, 0, 0, 0, 0, 203, 0,
295 -146, 277, 0, -112, 0, 0, 4, 205, -88, 0,
296 0, 0, 0, 0,
297};
298#define YYTABLESIZE1116 1116
299const short yytable[] =
300 { 27,
301 37, 40, 27, 62, 33, 41, 42, 38, 97, 98,
302 45, 63, 64, 173, 136, 137, 58, 145, 58, 53,
303 56, 57, 43, 60, 61, 103, 104, 90, 90, 79,
304 90, 159, 90, 47, 90, 189, 90, 90, 92, 58,
305 94, 37, 40, 194, 93, 93, 157, 99, 100, 185,
306 186, 59, 19, 20, 90, 82, 90, 90, 187, 102,
307 69, 101, 69, 83, 105, 106, 107, 108, 109, 110,
308 111, 112, 113, 114, 115, 116, 99, 34, 174, 99,
309 27, 121, 7, 35, 27, 120, 27, 47, 47, 122,
310 7, 123, 41, 128, 190, 131, 47, 61, 53, 61,
311 193, 63, 118, 63, 40, 99, 99, 40, 99, 99,
312 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
313 99, 143, 99, 99, 10, 96, 96, 131, 84, 98,
314 98, 20, 10, 153, 154, 20, 63, 64, 183, 20,
315 64, 131, 64, 161, 162, 163, 164, 165, 166, 48,
316 27, 49, 49, 49, 92, 50, 51, 20, 27, 86,
317 86, 49, 86, 86, 86, 86, 86, 86, 86, 128,
318 53, 93, 87, 53, 27, 119, 88, 117, 2, 38,
319 27, 3, 42, 4, 124, 42, 125, 5, 27, 6,
320 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
321 17, 18, 19, 20, 59, 21, 59, 22, 99, 99,
322 23, 99, 86, 99, 11, 99, 188, 99, 11, 24,
323 88, 54, 11, 15, 54, 25, 26, 15, 139, 78,
324 138, 15, 94, 94, 141, 99, 144, 99, 99, 152,
325 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
326 99, 99, 99, 155, 99, 99, 156, 101, 101, 65,
327 101, 169, 101, 65, 101, 160, 101, 65, 65, 66,
328 170, 67, 68, 69, 70, 71, 72, 172, 73, 74,
329 75, 76, 77, 78, 101, 65, 101, 101, 178, 101,
330 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
331 101, 101, 175, 101, 101, 44, 44, 179, 44, 44,
332 182, 184, 44, 44, 44, 44, 44, 191, 44, 44,
333 44, 44, 44, 44, 44, 44, 44, 44, 44, 13,
334 44, 192, 44, 13, 27, 44, 195, 13, 27, 196,
335 38, 51, 27, 39, 44, 52, 3, 68, 4, 36,
336 44, 44, 5, 56, 6, 7, 8, 68, 10, 11,
337 12, 13, 14, 15, 16, 17, 18, 19, 20, 60,
338 21, 60, 22, 3, 177, 23, 62, 135, 62, 5,
339 181, 6, 7, 52, 24, 0, 0, 12, 0, 0,
340 25, 26, 17, 18, 19, 20, 0, 95, 95, 0,
341 3, 95, 23, 0, 97, 97, 5, 0, 6, 7,
342 0, 24, 0, 0, 12, 0, 0, 25, 26, 17,
343 18, 19, 20, 75, 76, 77, 78, 3, 0, 23,
344 0, 0, 171, 5, 0, 6, 7, 0, 24, 0,
345 0, 12, 0, 0, 25, 26, 17, 18, 19, 20,
346 93, 93, 0, 93, 3, 93, 23, 93, 0, 93,
347 5, 0, 6, 7, 0, 24, 0, 0, 12, 0,
348 0, 25, 26, 17, 18, 19, 20, 93, 19, 93,
349 93, 44, 19, 23, 0, 0, 19, 5, 0, 6,
350 7, 0, 24, 0, 0, 12, 0, 0, 25, 26,
351 17, 18, 19, 20, 19, 0, 0, 0, 3, 0,
352 23, 0, 0, 0, 5, 0, 142, 7, 0, 24,
353 0, 0, 12, 0, 0, 25, 26, 17, 18, 19,
354 20, 70, 70, 0, 70, 0, 70, 23, 70, 0,
355 70, 0, 106, 106, 0, 0, 24, 106, 0, 0,
356 0, 106, 25, 26, 0, 0, 0, 0, 70, 0,
357 70, 70, 0, 70, 70, 70, 70, 70, 70, 106,
358 70, 70, 70, 70, 70, 70, 99, 99, 0, 99,
359 0, 99, 0, 99, 0, 99, 73, 74, 75, 76,
360 77, 78, 0, 0, 0, 78, 78, 0, 78, 0,
361 78, 0, 78, 99, 78, 99, 99, 0, 99, 99,
362 99, 99, 99, 99, 0, 99, 99, 99, 99, 99,
363 99, 0, 78, 0, 78, 78, 0, 78, 78, 78,
364 78, 78, 78, 0, 78, 78, 78, 78, 78, 79,
365 79, 66, 79, 0, 79, 66, 79, 0, 79, 66,
366 0, 0, 0, 0, 0, 0, 80, 80, 0, 80,
367 0, 80, 0, 80, 0, 80, 79, 66, 79, 79,
368 0, 79, 79, 79, 79, 79, 79, 0, 79, 79,
369 79, 79, 79, 80, 0, 80, 80, 0, 80, 80,
370 80, 80, 80, 80, 0, 80, 80, 80, 80, 80,
371 81, 81, 31, 81, 0, 81, 31, 81, 0, 81,
372 31, 0, 0, 0, 0, 0, 0, 0, 70, 0,
373 0, 0, 70, 0, 0, 0, 70, 81, 31, 81,
374 81, 0, 81, 81, 81, 81, 81, 81, 85, 81,
375 81, 81, 81, 81, 70, 0, 70, 70, 0, 70,
376 70, 70, 70, 70, 70, 127, 70, 70, 70, 70,
377 70, 70, 0, 0, 65, 66, 0, 67, 68, 69,
378 70, 71, 72, 133, 73, 74, 75, 76, 77, 78,
379 0, 65, 66, 0, 67, 68, 69, 70, 71, 72,
380 134, 73, 74, 75, 76, 77, 78, 0, 0, 65,
381 66, 0, 67, 68, 69, 70, 71, 72, 0, 73,
382 74, 75, 76, 77, 78, 0, 65, 66, 0, 67,
383 68, 69, 70, 71, 72, 0, 73, 74, 75, 76,
384 77, 78, 76, 76, 17, 76, 0, 76, 17, 76,
385 0, 76, 17, 0, 0, 0, 77, 77, 0, 77,
386 0, 77, 0, 77, 0, 77, 0, 0, 0, 76,
387 17, 76, 76, 0, 76, 76, 76, 76, 76, 76,
388 126, 76, 76, 77, 0, 77, 77, 0, 77, 77,
389 77, 77, 77, 77, 0, 77, 77, 0, 0, 0,
390 0, 0, 65, 66, 0, 67, 68, 69, 70, 71,
391 72, 0, 73, 74, 75, 76, 77, 78, 86, 86,
392 0, 86, 0, 86, 0, 86, 0, 86, 0, 96,
393 96, 0, 96, 0, 96, 0, 96, 0, 96, 0,
394 0, 0, 0, 0, 0, 86, 0, 86, 86, 0,
395 86, 86, 86, 86, 86, 86, 96, 0, 96, 96,
396 98, 98, 0, 98, 0, 98, 0, 98, 0, 98,
397 94, 94, 0, 94, 0, 94, 0, 94, 0, 94,
398 0, 0, 0, 0, 0, 0, 0, 98, 0, 98,
399 98, 0, 0, 0, 0, 0, 0, 94, 0, 94,
400 94, 95, 95, 0, 95, 0, 95, 0, 95, 0,
401 95, 97, 97, 0, 97, 0, 97, 0, 97, 0,
402 97, 0, 0, 0, 0, 0, 0, 0, 95, 0,
403 95, 95, 0, 0, 0, 0, 0, 0, 97, 0,
404 97, 97, 91, 91, 0, 91, 0, 91, 0, 91,
405 0, 91, 92, 92, 0, 92, 0, 92, 0, 92,
406 0, 92, 0, 0, 0, 0, 0, 0, 0, 91,
407 0, 91, 91, 0, 0, 0, 0, 0, 0, 92,
408 0, 92, 65, 66, 0, 146, 147, 148, 149, 150,
409 151, 0, 73, 74, 75, 76, 77, 78, 66, 0,
410 67, 68, 69, 70, 71, 72, 0, 73, 74, 75,
411 76, 77, 78, 67, 68, 69, 70, 71, 72, 0,
412 73, 74, 75, 76, 77, 78,
413};
414const short yycheck[] =
415 { 1,
416 3, 259, 4, 295, 1, 263, 267, 4, 48, 49,
417 13, 303, 304, 160, 103, 104, 258, 130, 260, 22,
418 23, 24, 259, 25, 26, 65, 66, 257, 258, 267,
419 260, 144, 262, 259, 264, 182, 266, 40, 41, 267,
420 43, 44, 259, 190, 286, 287, 263, 50, 51, 257,
421 258, 279, 280, 281, 284, 258, 286, 287, 266, 62,
422 258, 257, 260, 266, 67, 68, 69, 70, 71, 72,
423 73, 74, 75, 76, 77, 78, 257, 266, 167, 260,
424 82, 84, 258, 272, 86, 82, 88, 257, 258, 86,
425 266, 88, 263, 96, 183, 98, 266, 258, 101, 260,
426 189, 258, 260, 260, 257, 286, 287, 260, 289, 290,
427 291, 292, 293, 294, 295, 296, 297, 298, 299, 300,
428 301, 124, 303, 304, 258, 286, 287, 130, 295, 286,
429 287, 258, 266, 136, 137, 262, 303, 304, 178, 266,
430 258, 144, 260, 146, 147, 148, 149, 150, 151, 259,
431 152, 259, 257, 258, 157, 259, 259, 284, 160, 286,
432 287, 266, 289, 290, 291, 292, 293, 294, 258, 172,
433 257, 259, 262, 260, 176, 257, 266, 263, 256, 176,
434 182, 259, 257, 261, 257, 260, 260, 265, 190, 267,
435 268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
436 278, 279, 280, 281, 258, 283, 260, 285, 257, 258,
437 288, 260, 258, 262, 258, 264, 262, 266, 262, 297,
438 266, 257, 266, 258, 260, 303, 304, 262, 266, 301,
439 264, 266, 286, 287, 267, 284, 258, 286, 287, 260,
440 289, 290, 291, 292, 293, 294, 295, 296, 297, 298,
441 299, 300, 301, 261, 303, 304, 263, 257, 258, 258,
442 260, 266, 262, 262, 264, 260, 266, 266, 286, 287,
443 264, 289, 290, 291, 292, 293, 294, 258, 296, 297,
444 298, 299, 300, 301, 284, 284, 286, 287, 284, 289,
445 290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
446 300, 301, 282, 303, 304, 258, 259, 267, 261, 262,
447 260, 263, 265, 266, 267, 268, 269, 264, 271, 272,
448 273, 274, 275, 276, 277, 278, 279, 280, 281, 258,
449 283, 267, 285, 262, 258, 288, 263, 266, 262, 264,
450 260, 260, 266, 260, 297, 260, 259, 258, 261, 261,
451 303, 304, 265, 258, 267, 268, 269, 260, 271, 272,
452 273, 274, 275, 276, 277, 278, 279, 280, 281, 258,
453 283, 260, 285, 259, 172, 288, 258, 101, 260, 265,
454 176, 267, 268, 269, 297, -1, -1, 273, -1, -1,
455 303, 304, 278, 279, 280, 281, -1, 286, 287, -1,
456 259, 260, 288, -1, 286, 287, 265, -1, 267, 268,
457 -1, 297, -1, -1, 273, -1, -1, 303, 304, 278,
458 279, 280, 281, 298, 299, 300, 301, 259, -1, 288,
459 -1, -1, 264, 265, -1, 267, 268, -1, 297, -1,
460 -1, 273, -1, -1, 303, 304, 278, 279, 280, 281,
461 257, 258, -1, 260, 259, 262, 288, 264, -1, 266,
462 265, -1, 267, 268, -1, 297, -1, -1, 273, -1,
463 -1, 303, 304, 278, 279, 280, 281, 284, 258, 286,
464 287, 259, 262, 288, -1, -1, 266, 265, -1, 267,
465 268, -1, 297, -1, -1, 273, -1, -1, 303, 304,
466 278, 279, 280, 281, 284, -1, -1, -1, 259, -1,
467 288, -1, -1, -1, 265, -1, 267, 268, -1, 297,
468 -1, -1, 273, -1, -1, 303, 304, 278, 279, 280,
469 281, 257, 258, -1, 260, -1, 262, 288, 264, -1,
470 266, -1, 257, 258, -1, -1, 297, 262, -1, -1,
471 -1, 266, 303, 304, -1, -1, -1, -1, 284, -1,
472 286, 287, -1, 289, 290, 291, 292, 293, 294, 284,
473 296, 297, 298, 299, 300, 301, 257, 258, -1, 260,
474 -1, 262, -1, 264, -1, 266, 296, 297, 298, 299,
475 300, 301, -1, -1, -1, 257, 258, -1, 260, -1,
476 262, -1, 264, 284, 266, 286, 287, -1, 289, 290,
477 291, 292, 293, 294, -1, 296, 297, 298, 299, 300,
478 301, -1, 284, -1, 286, 287, -1, 289, 290, 291,
479 292, 293, 294, -1, 296, 297, 298, 299, 300, 257,
480 258, 258, 260, -1, 262, 262, 264, -1, 266, 266,
481 -1, -1, -1, -1, -1, -1, 257, 258, -1, 260,
482 -1, 262, -1, 264, -1, 266, 284, 284, 286, 287,
483 -1, 289, 290, 291, 292, 293, 294, -1, 296, 297,
484 298, 299, 300, 284, -1, 286, 287, -1, 289, 290,
485 291, 292, 293, 294, -1, 296, 297, 298, 299, 300,
486 257, 258, 258, 260, -1, 262, 262, 264, -1, 266,
487 266, -1, -1, -1, -1, -1, -1, -1, 258, -1,
488 -1, -1, 262, -1, -1, -1, 266, 284, 284, 286,
489 287, -1, 289, 290, 291, 292, 293, 294, 260, 296,
490 297, 298, 299, 300, 284, -1, 286, 287, -1, 289,
491 290, 291, 292, 293, 294, 260, 296, 297, 298, 299,
492 300, 301, -1, -1, 286, 287, -1, 289, 290, 291,
493 292, 293, 294, 260, 296, 297, 298, 299, 300, 301,
494 -1, 286, 287, -1, 289, 290, 291, 292, 293, 294,
495 260, 296, 297, 298, 299, 300, 301, -1, -1, 286,
496 287, -1, 289, 290, 291, 292, 293, 294, -1, 296,
497 297, 298, 299, 300, 301, -1, 286, 287, -1, 289,
498 290, 291, 292, 293, 294, -1, 296, 297, 298, 299,
499 300, 301, 257, 258, 258, 260, -1, 262, 262, 264,
500 -1, 266, 266, -1, -1, -1, 257, 258, -1, 260,
501 -1, 262, -1, 264, -1, 266, -1, -1, -1, 284,
502 284, 286, 287, -1, 289, 290, 291, 292, 293, 294,
503 264, 296, 297, 284, -1, 286, 287, -1, 289, 290,
504 291, 292, 293, 294, -1, 296, 297, -1, -1, -1,
505 -1, -1, 286, 287, -1, 289, 290, 291, 292, 293,
506 294, -1, 296, 297, 298, 299, 300, 301, 257, 258,
507 -1, 260, -1, 262, -1, 264, -1, 266, -1, 257,
508 258, -1, 260, -1, 262, -1, 264, -1, 266, -1,
509 -1, -1, -1, -1, -1, 284, -1, 286, 287, -1,
510 289, 290, 291, 292, 293, 294, 284, -1, 286, 287,
511 257, 258, -1, 260, -1, 262, -1, 264, -1, 266,
512 257, 258, -1, 260, -1, 262, -1, 264, -1, 266,
513 -1, -1, -1, -1, -1, -1, -1, 284, -1, 286,
514 287, -1, -1, -1, -1, -1, -1, 284, -1, 286,
515 287, 257, 258, -1, 260, -1, 262, -1, 264, -1,
516 266, 257, 258, -1, 260, -1, 262, -1, 264, -1,
517 266, -1, -1, -1, -1, -1, -1, -1, 284, -1,
518 286, 287, -1, -1, -1, -1, -1, -1, 284, -1,
519 286, 287, 257, 258, -1, 260, -1, 262, -1, 264,
520 -1, 266, 257, 258, -1, 260, -1, 262, -1, 264,
521 -1, 266, -1, -1, -1, -1, -1, -1, -1, 284,
522 -1, 286, 287, -1, -1, -1, -1, -1, -1, 284,
523 -1, 286, 286, 287, -1, 289, 290, 291, 292, 293,
524 294, -1, 296, 297, 298, 299, 300, 301, 287, -1,
525 289, 290, 291, 292, 293, 294, -1, 296, 297, 298,
526 299, 300, 301, 289, 290, 291, 292, 293, 294, -1,
527 296, 297, 298, 299, 300, 301,
528};
529#define YYFINAL1 1
530#ifndef YYDEBUG0
531#define YYDEBUG0 0
532#endif
533#define YYMAXTOKEN304 304
534#if YYDEBUG0
535const char * const yyname[] =
536 {
537"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5380,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5390,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5400,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5420,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5430,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"COMMA","SEMICOLON","LPAR","RPAR",
544"LBRACE","RBRACE","LBRACKET","RBRACKET","DOT","NEWLINE","LETTER","NUMBER",
545"STRING","DEFINE","BREAK","QUIT","LENGTH","RETURN","FOR","IF","WHILE","SQRT",
546"SCALE","IBASE","OBASE","AUTO","CONTINUE","ELSE","PRINT","BOOL_OR","BOOL_AND",
547"BOOL_NOT","EQUALS","LESS_EQ","GREATER_EQ","UNEQUALS","LESS","GREATER",
548"ASSIGN_OP","PLUS","MINUS","MULTIPLY","DIVIDE","REMAINDER","EXPONENT","UMINUS",
549"INCR","DECR",
550};
551const char * const yyrule[] =
552 {"$accept : program",
553"program :",
554"program : program input_item",
555"input_item : semicolon_list NEWLINE",
556"input_item : function",
557"input_item : error NEWLINE",
558"input_item : error QUIT",
559"semicolon_list :",
560"semicolon_list : statement",
561"semicolon_list : semicolon_list SEMICOLON statement",
562"semicolon_list : semicolon_list SEMICOLON",
563"statement_list :",
564"statement_list : statement",
565"statement_list : statement_list NEWLINE",
566"statement_list : statement_list NEWLINE statement",
567"statement_list : statement_list SEMICOLON",
568"statement_list : statement_list SEMICOLON statement",
569"opt_statement :",
570"opt_statement : statement",
571"statement : expression",
572"statement : named_expression ASSIGN_OP expression",
573"statement : STRING",
574"statement : BREAK",
575"statement : CONTINUE",
576"statement : QUIT",
577"statement : RETURN return_expression",
578"statement : FOR LPAR alloc_macro opt_expression SEMICOLON opt_relational_expression SEMICOLON opt_expression RPAR opt_statement pop_nesting",
579"statement : IF LPAR alloc_macro pop_nesting relational_expression RPAR opt_statement",
580"statement : IF LPAR alloc_macro pop_nesting relational_expression RPAR opt_statement ELSE alloc_macro pop_nesting opt_statement",
581"statement : WHILE LPAR alloc_macro relational_expression RPAR opt_statement pop_nesting",
582"statement : LBRACE statement_list RBRACE",
583"statement : PRINT print_expression_list",
584"alloc_macro :",
585"pop_nesting :",
586"function : function_header opt_parameter_list RPAR opt_newline LBRACE NEWLINE opt_auto_define_list statement_list RBRACE",
587"function_header : DEFINE LETTER LPAR",
588"opt_newline :",
589"opt_newline : NEWLINE",
590"opt_parameter_list :",
591"opt_parameter_list : parameter_list",
592"parameter_list : LETTER",
593"parameter_list : LETTER LBRACKET RBRACKET",
594"parameter_list : parameter_list COMMA LETTER",
595"parameter_list : parameter_list COMMA LETTER LBRACKET RBRACKET",
596"opt_auto_define_list :",
597"opt_auto_define_list : AUTO define_list NEWLINE",
598"opt_auto_define_list : AUTO define_list SEMICOLON",
599"define_list : LETTER",
600"define_list : LETTER LBRACKET RBRACKET",
601"define_list : define_list COMMA LETTER",
602"define_list : define_list COMMA LETTER LBRACKET RBRACKET",
603"opt_argument_list :",
604"opt_argument_list : argument_list",
605"argument_list : expression",
606"argument_list : argument_list COMMA expression",
607"argument_list : argument_list COMMA LETTER LBRACKET RBRACKET",
608"opt_relational_expression :",
609"opt_relational_expression : relational_expression",
610"relational_expression : expression EQUALS expression",
611"relational_expression : expression UNEQUALS expression",
612"relational_expression : expression LESS expression",
613"relational_expression : expression LESS_EQ expression",
614"relational_expression : expression GREATER expression",
615"relational_expression : expression GREATER_EQ expression",
616"relational_expression : expression",
617"return_expression :",
618"return_expression : expression",
619"return_expression : LPAR RPAR",
620"opt_expression :",
621"opt_expression : expression",
622"expression : named_expression",
623"expression : DOT",
624"expression : NUMBER",
625"expression : LPAR expression RPAR",
626"expression : LETTER LPAR opt_argument_list RPAR",
627"expression : MINUS expression",
628"expression : expression PLUS expression",
629"expression : expression MINUS expression",
630"expression : expression MULTIPLY expression",
631"expression : expression DIVIDE expression",
632"expression : expression REMAINDER expression",
633"expression : expression EXPONENT expression",
634"expression : INCR named_expression",
635"expression : DECR named_expression",
636"expression : named_expression INCR",
637"expression : named_expression DECR",
638"expression : named_expression ASSIGN_OP expression",
639"expression : LENGTH LPAR expression RPAR",
640"expression : SQRT LPAR expression RPAR",
641"expression : SCALE LPAR expression RPAR",
642"expression : BOOL_NOT expression",
643"expression : expression BOOL_AND alloc_macro pop_nesting expression",
644"expression : expression BOOL_OR alloc_macro pop_nesting expression",
645"expression : expression EQUALS expression",
646"expression : expression UNEQUALS expression",
647"expression : expression LESS expression",
648"expression : expression LESS_EQ expression",
649"expression : expression GREATER expression",
650"expression : expression GREATER_EQ expression",
651"named_expression : LETTER",
652"named_expression : LETTER LBRACKET expression RBRACKET",
653"named_expression : SCALE",
654"named_expression : IBASE",
655"named_expression : OBASE",
656"print_expression_list : print_expression",
657"print_expression_list : print_expression_list COMMA print_expression",
658"print_expression : expression",
659"print_expression : STRING",
660};
661#endif
662#ifdef YYSTACKSIZE10000
663#undef YYMAXDEPTH10000
664#define YYMAXDEPTH10000 YYSTACKSIZE10000
665#else
666#ifdef YYMAXDEPTH10000
667#define YYSTACKSIZE10000 YYMAXDEPTH10000
668#else
669#define YYSTACKSIZE10000 10000
670#define YYMAXDEPTH10000 10000
671#endif
672#endif
673#define YYINITSTACKSIZE200 200
674/* LINTUSED */
675int yydebug;
676int yynerrs;
677int yyerrflag;
678int yychar;
679short *yyssp;
680YYSTYPE *yyvsp;
681YYSTYPE yyval;
682YYSTYPE yylval;
683short *yyss;
684short *yysslim;
685YYSTYPE *yyvs;
686unsigned int yystacksize;
687int yyparse(void);
688#line 743 "/usr/src/usr.bin/bc/bc.y"
689
690
691static void
692grow(void)
693{
694 struct tree *p;
695 size_t newsize;
696
697 if (current == instr_sz) {
698 newsize = instr_sz * 2 + 1;
699 p = reallocarray(instructions, newsize, sizeof(*p));
700 if (p == NULL((void *)0)) {
701 free(instructions);
702 err(1, NULL((void *)0));
703 }
704 instructions = p;
705 instr_sz = newsize;
706 }
707}
708
709static ssize_t
710cs(const char *str)
711{
712 grow();
713 instructions[current].index = CONST_STRING((ssize_t) -2);
714 instructions[current].u.cstr = str;
715 return current++;
716}
717
718static ssize_t
719as(const char *str)
720{
721 grow();
722 instructions[current].index = ALLOC_STRING((ssize_t) -3);
723 instructions[current].u.astr = strdup(str);
724 if (instructions[current].u.astr == NULL((void *)0))
725 err(1, NULL((void *)0));
726 return current++;
727}
728
729static ssize_t
730node(ssize_t arg, ...)
731{
732 va_list ap;
733 ssize_t ret;
734
735 va_start(ap, arg)__builtin_va_start((ap), arg);
736
737 ret = current;
738 grow();
739 instructions[current++].index = arg;
740
741 do {
742 arg = va_arg(ap, ssize_t)__builtin_va_arg((ap), ssize_t);
743 grow();
744 instructions[current++].index = arg;
745 } while (arg != END_NODE((ssize_t) -1));
746
747 va_end(ap)__builtin_va_end((ap));
748 return ret;
749}
750
751static void
752emit(ssize_t i, int level)
753{
754 if (level > 1000)
755 errx(1, "internal error: tree level > 1000");
756 if (instructions[i].index >= 0) {
757 while (instructions[i].index != END_NODE((ssize_t) -1) &&
758 instructions[i].index != i) {
759 emit(instructions[i].index, level + 1);
760 i++;
761 }
762 } else if (instructions[i].index != END_NODE((ssize_t) -1))
763 fputs(instructions[i].u.cstr, stdout(&__sF[1]));
764}
765
766static void
767emit_macro(int node, ssize_t code)
768{
769 putchar('[')(!__isthreaded ? __sputc('[', (&__sF[1])) : (putc)('[', (
&__sF[1])))
;
770 emit(code, 0);
771 printf("]s%s\n", instructions[node].u.cstr);
772 nesting--;
773}
774
775static void
776free_tree(void)
777{
778 ssize_t i;
779
780 for (i = 0; i < current; i++)
781 if (instructions[i].index == ALLOC_STRING((ssize_t) -3))
782 free(instructions[i].u.astr);
783 current = 0;
784}
785
786static ssize_t
787numnode(int num)
788{
789 const char *p;
790
791 if (num < 10)
792 p = str_table['0' + num];
793 else if (num < 16)
794 p = str_table['A' - 10 + num];
795 else
796 errx(1, "internal error: break num > 15");
797 return node(cs(" "), cs(p), END_NODE((ssize_t) -1));
798}
799
800
801static ssize_t
802lookup(char * str, size_t len, char type)
803{
804 ENTRY entry, *found;
28
'entry' initialized here
805 u_short num;
806 u_char *p;
807
808 /* The scanner allocated an extra byte already */
809 if (str[len-1] != type) {
29
Assuming the condition is false
30
Taking false branch
810 str[len] = type;
811 str[len+1] = '\0';
812 }
813 entry.key = str;
814 found = hsearch(entry, FIND);
31
Passed-by-value struct argument contains uninitialized data (e.g., field: 'data')
815 if (found == NULL((void *)0)) {
816 if (var_count == MAX_VARIABLES((256-4) * (256-4)))
817 errx(1, "too many variables");
818 p = malloc(4);
819 if (p == NULL((void *)0))
820 err(1, NULL((void *)0));
821 num = var_count++;
822 p[0] = 255;
823 p[1] = ENCODE(num / VAR_BASE + 1)((num / (256-4) + 1) < '[' ? (num / (256-4) + 1) : (num / (
256-4) + 1) + 3);
;
824 p[2] = ENCODE(num % VAR_BASE + 1)((num % (256-4) + 1) < '[' ? (num % (256-4) + 1) : (num % (
256-4) + 1) + 3);
;
825 p[3] = '\0';
826
827 entry.data = (char *)p;
828 entry.key = strdup(str);
829 if (entry.key == NULL((void *)0))
830 err(1, NULL((void *)0));
831 found = hsearch(entry, ENTER);
832 if (found == NULL((void *)0))
833 err(1, NULL((void *)0));
834 }
835 return cs(found->data);
836}
837
838static ssize_t
839letter_node(char *str)
840{
841 size_t len;
842
843 len = strlen(str);
844 if (len == 1 && str[0] != '_')
845 return cs(str_table[(int)str[0]]);
846 else
847 return lookup(str, len, 'L');
848}
849
850static ssize_t
851array_node(char *str)
852{
853 size_t len;
854
855 len = strlen(str);
856 if (len == 1 && str[0] != '_')
26
Assuming 'len' is not equal to 1
857 return cs(str_table[(int)str[0] - 'a' + ARRAY_CHAR0xa1]);
858 else
859 return lookup(str, len, 'A');
27
Calling 'lookup'
860}
861
862static ssize_t
863function_node(char *str)
864{
865 size_t len;
866
867 len = strlen(str);
868 if (len == 1 && str[0] != '_')
869 return cs(str_table[(int)str[0] - 'a' + FUNC_CHAR0x01]);
870 else
871 return lookup(str, len, 'F');
872}
873
874static void
875add_par(ssize_t n)
876{
877 prologue = node(cs("S"), n, prologue, END_NODE((ssize_t) -1));
878 epilogue = node(epilogue, cs("L"), n, cs("s."), END_NODE((ssize_t) -1));
879}
880
881static void
882add_local(ssize_t n)
883{
884 prologue = node(cs("0S"), n, prologue, END_NODE((ssize_t) -1));
885 epilogue = node(epilogue, cs("L"), n, cs("s."), END_NODE((ssize_t) -1));
886}
887
888void
889yyerror(char *s)
890{
891 char *str, *p;
892 int n;
893
894 if (yyin != NULL((void *)0) && feof(yyin)(!__isthreaded ? (((yyin)->_flags & 0x0020) != 0) : (feof
)(yyin))
)
895 n = asprintf(&str, "%s: %s:%d: %s: unexpected EOF",
896 __progname, filename, lineno, s);
897 else if (yytext[0] == '\n')
898 n = asprintf(&str,
899 "%s: %s:%d: %s: newline unexpected",
900 __progname, filename, lineno, s);
901 else if (isspace((unsigned char)yytext[0]) ||
902 !isprint((unsigned char)yytext[0]))
903 n = asprintf(&str,
904 "%s: %s:%d: %s: ascii char 0x%02x unexpected",
905 __progname, filename, lineno, s, yytext[0] & 0xff);
906 else
907 n = asprintf(&str, "%s: %s:%d: %s: %s unexpected",
908 __progname, filename, lineno, s, yytext);
909 if (n == -1)
910 err(1, NULL((void *)0));
911
912 fputs("c[", stdout(&__sF[1]));
913 for (p = str; *p != '\0'; p++) {
914 if (*p == '[' || *p == ']' || *p =='\\')
915 putchar('\\')(!__isthreaded ? __sputc('\\', (&__sF[1])) : (putc)('\\',
(&__sF[1])))
;
916 putchar(*p)(!__isthreaded ? __sputc(*p, (&__sF[1])) : (putc)(*p, (&
__sF[1])))
;
917 }
918 fputs("]ec\n", stdout(&__sF[1]));
919 free(str);
920}
921
922void
923fatal(const char *s)
924{
925 errx(1, "%s:%d: %s", filename, lineno, s);
926}
927
928static void
929warning(const char *s)
930{
931 warnx("%s:%d: %s", filename, lineno, s);
932}
933
934static void
935init(void)
936{
937 int i;
938
939 for (i = 0; i < UCHAR_MAX0xff; i++) {
940 str_table[i][0] = i;
941 str_table[i][1] = '\0';
942 }
943 if (hcreate(1 << 16) == 0)
944 err(1, NULL((void *)0));
945}
946
947
948static __dead__attribute__((__noreturn__)) void
949usage(void)
950{
951 fprintf(stderr(&__sF[2]), "usage: %s [-cl] [-e expression] [file ...]\n",
952 __progname);
953 exit(1);
954}
955
956static char *
957escape(const char *str)
958{
959 char *ret, *p;
960
961 ret = malloc(strlen(str) + 1);
962 if (ret == NULL((void *)0))
963 err(1, NULL((void *)0));
964
965 p = ret;
966 while (*str != '\0') {
967 /*
968 * We get _escaped_ strings here. Single backslashes are
969 * already converted to double backslashes
970 */
971 if (*str == '\\') {
972 if (*++str == '\\') {
973 switch (*++str) {
974 case 'a':
975 *p++ = '\a';
976 break;
977 case 'b':
978 *p++ = '\b';
979 break;
980 case 'f':
981 *p++ = '\f';
982 break;
983 case 'n':
984 *p++ = '\n';
985 break;
986 case 'q':
987 *p++ = '"';
988 break;
989 case 'r':
990 *p++ = '\r';
991 break;
992 case 't':
993 *p++ = '\t';
994 break;
995 case '\\':
996 *p++ = '\\';
997 break;
998 }
999 if (*str == '\0')
1000 break;
1001 str++;
1002 } else {
1003 *p++ = '\\';
1004 *p++ = *str++;
1005 }
1006 } else
1007 *p++ = *str++;
1008 }
1009 *p = '\0';
1010 return ret;
1011}
1012
1013static void
1014sigchld(int signo)
1015{
1016 pid_t pid;
1017 int status, save_errno = errno(*__errno());
1018
1019 for (;;) {
1020 pid = waitpid(dc, &status, WCONTINUED0x08 | WNOHANG0x01);
1021 if (pid == -1) {
1022 if (errno(*__errno()) == EINTR4)
1023 continue;
1024 _exit(0);
1025 } else if (pid == 0)
1026 break;
1027 if (WIFEXITED(status)(((status) & 0177) == 0) || WIFSIGNALED(status)(((status) & 0177) != 0177 && ((status) & 0177
) != 0)
)
1028 _exit(0);
1029 else
1030 break;
1031 }
1032 errno(*__errno()) = save_errno;
1033}
1034
1035static const char *
1036dummy_prompt(void)
1037{
1038
1039 return ("");
1040}
1041
1042int
1043main(int argc, char *argv[])
1044{
1045 int i, ch;
1046 int p[2];
1047 char *q;
1048
1049 if (pledge("stdio rpath proc tty", NULL((void *)0)) == -1)
1050 err(1, "pledge");
1051
1052 init();
1053 setvbuf(stdout(&__sF[1]), NULL((void *)0), _IOLBF1, 0);
1054
1055 sargv = reallocarray(NULL((void *)0), argc, sizeof(char *));
1056 if (sargv == NULL((void *)0))
1057 err(1, NULL((void *)0));
1058
1059 if ((cmdexpr = strdup("")) == NULL((void *)0))
1060 err(1, NULL((void *)0));
1061 /* The d debug option is 4.4 BSD bc(1) compatible */
1062 while ((ch = getopt(argc, argv, "cde:l")) != -1) {
1063 switch (ch) {
1064 case 'c':
1065 case 'd':
1066 do_fork = false0;
1067 break;
1068 case 'e':
1069 q = cmdexpr;
1070 if (asprintf(&cmdexpr, "%s%s\n", cmdexpr, optarg) == -1)
1071 err(1, NULL((void *)0));
1072 free(q);
1073 break;
1074 case 'l':
1075 sargv[sargc++] = _PATH_LIBB"/usr/share/misc/bc.library";
1076 break;
1077 default:
1078 usage();
1079 }
1080 }
1081
1082 argc -= optind;
1083 argv += optind;
1084
1085 interactive = isatty(STDIN_FILENO0) && isatty(STDOUT_FILENO1) &&
1086 isatty(STDERR_FILENO2);
1087 for (i = 0; i < argc; i++)
1088 sargv[sargc++] = argv[i];
1089
1090 if (do_fork) {
1091 if (pipe(p) == -1)
1092 err(1, "cannot create pipe");
1093 dc = fork();
1094 if (dc == -1)
1095 err(1, "cannot fork");
1096 else if (dc != 0) {
1097 signal(SIGCHLD20, sigchld);
1098 close(STDOUT_FILENO1);
1099 dup(p[1]);
1100 close(p[0]);
1101 close(p[1]);
1102 } else {
1103 char *dc_argv[] = { "dc", "-x", NULL((void *)0) };
1104 extern int dc_main(int, char **);
1105
1106 if (pledge("stdio", NULL((void *)0)) == -1)
1107 err(1, "pledge");
1108
1109 close(STDIN_FILENO0);
1110 dup(p[0]);
1111 close(p[0]);
1112 close(p[1]);
1113
1114 exit (dc_main(2, dc_argv));
1115 }
1116 }
1117 if (interactive) {
1118 gettty(&ttysaved);
1119 el = el_init("bc", stdin(&__sF[0]), stderr(&__sF[2]), stderr(&__sF[2]));
1120 hist = history_init();
1121 history(hist, &he, H_SETSIZE1, 100);
1122 el_set(el, EL_HIST10, history, hist);
1123 el_set(el, EL_EDITOR2, "emacs");
1124 el_set(el, EL_SIGNAL3, 0);
1125 el_set(el, EL_PROMPT0, dummy_prompt);
1126 el_set(el, EL_ADDFN9, "bc_eof", "", bc_eof);
1127 el_set(el, EL_BIND4, "^D", "bc_eof", NULL((void *)0));
1128 el_source(el, NULL((void *)0));
1129 }
1130
1131 if (pledge("stdio rpath tty", NULL((void *)0)) == -1)
1132 err(1, "pledge");
1133
1134 yywrap();
1135 return yyparse();
1136}
1137#line 1130 "bc.c"
1138/* allocate initial stack or double stack size, up to YYMAXDEPTH */
1139static int yygrowstack(void)
1140{
1141 unsigned int newsize;
1142 long sslen;
1143 short *newss;
1144 YYSTYPE *newvs;
1145
1146 if ((newsize = yystacksize) == 0)
1147 newsize = YYINITSTACKSIZE200;
1148 else if (newsize >= YYMAXDEPTH10000)
1149 return -1;
1150 else if ((newsize *= 2) > YYMAXDEPTH10000)
1151 newsize = YYMAXDEPTH10000;
1152 sslen = yyssp - yyss;
1153#ifdef SIZE_MAX0xffffffffffffffffUL
1154#define YY_SIZE_MAX0xffffffffffffffffUL SIZE_MAX0xffffffffffffffffUL
1155#else
1156#define YY_SIZE_MAX0xffffffffffffffffUL 0xffffffffU
1157#endif
1158 if (newsize && YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newss)
1159 goto bail;
1160 newss = (short *)realloc(yyss, newsize * sizeof *newss);
1161 if (newss == NULL((void *)0))
1162 goto bail;
1163 yyss = newss;
1164 yyssp = newss + sslen;
1165 if (newsize && YY_SIZE_MAX0xffffffffffffffffUL / newsize < sizeof *newvs)
1166 goto bail;
1167 newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs);
1168 if (newvs == NULL((void *)0))
1169 goto bail;
1170 yyvs = newvs;
1171 yyvsp = newvs + sslen;
1172 yystacksize = newsize;
1173 yysslim = yyss + newsize - 1;
1174 return 0;
1175bail:
1176 if (yyss)
1177 free(yyss);
1178 if (yyvs)
1179 free(yyvs);
1180 yyss = yyssp = NULL((void *)0);
1181 yyvs = yyvsp = NULL((void *)0);
1182 yystacksize = 0;
1183 return -1;
1184}
1185
1186#define YYABORTgoto yyabort goto yyabort
1187#define YYREJECTgoto yyabort goto yyabort
1188#define YYACCEPTgoto yyaccept goto yyaccept
1189#define YYERRORgoto yyerrlab goto yyerrlab
1190int
1191yyparse(void)
1192{
1193 int yym, yyn, yystate;
1194#if YYDEBUG0
1195 const char *yys;
1196
1197 if ((yys = getenv("YYDEBUG")))
1198 {
1199 yyn = *yys;
1200 if (yyn >= '0' && yyn <= '9')
1201 yydebug = yyn - '0';
1202 }
1203#endif /* YYDEBUG */
1204
1205 yynerrs = 0;
1206 yyerrflag = 0;
1207 yychar = (-1);
1208
1209 if (yyss == NULL((void *)0) && yygrowstack()) goto yyoverflow;
1
Assuming 'yyss' is not equal to NULL
1210 yyssp = yyss;
1211 yyvsp = yyvs;
1212 *yyssp = yystate = 0;
1213
1214yyloop:
1215 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
2
Taking true branch
3
Control jumps to line 1322
13
Taking false branch
1216 if (yychar
13.1
'yychar' is >= 0
< 0)
1217 {
1218 if ((yychar = yylex()) < 0) yychar = 0;
1219#if YYDEBUG0
1220 if (yydebug)
1221 {
1222 yys = 0;
1223 if (yychar <= YYMAXTOKEN304) yys = yyname[yychar];
1224 if (!yys) yys = "illegal-symbol";
1225 printf("%sdebug: state %d, reading %d (%s)\n",
1226 YYPREFIX"yy", yystate, yychar, yys);
1227 }
1228#endif
1229 }
1230 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
14
Assuming 'yyn' is not equal to 0
15
Assuming the condition is true
1231 yyn <= YYTABLESIZE1116 && yycheck[yyn] == yychar)
16
Assuming 'yyn' is > YYTABLESIZE
1232 {
1233#if YYDEBUG0
1234 if (yydebug)
1235 printf("%sdebug: state %d, shifting to state %d\n",
1236 YYPREFIX"yy", yystate, yytable[yyn]);
1237#endif
1238 if (yyssp >= yysslim && yygrowstack())
1239 {
1240 goto yyoverflow;
1241 }
1242 *++yyssp = yystate = yytable[yyn];
1243 *++yyvsp = yylval;
1244 yychar = (-1);
1245 if (yyerrflag > 0) --yyerrflag;
1246 goto yyloop;
1247 }
1248 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
17
Assuming 'yyn' is not equal to 0
20
Taking true branch
1249 yyn <= YYTABLESIZE1116 && yycheck[yyn] == yychar)
18
Assuming 'yyn' is <= YYTABLESIZE
19
Assuming the condition is true
1250 {
1251 yyn = yytable[yyn];
1252 goto yyreduce;
21
Control jumps to line 1322
1253 }
1254 if (yyerrflag) goto yyinrecovery;
1255#if defined(__GNUC__4)
1256 goto yynewerror;
1257#endif
1258yynewerror:
1259 yyerror("syntax error");
1260#if defined(__GNUC__4)
1261 goto yyerrlab;
1262#endif
1263yyerrlab:
1264 ++yynerrs;
1265yyinrecovery:
1266 if (yyerrflag < 3)
1267 {
1268 yyerrflag = 3;
1269 for (;;)
1270 {
1271 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE256) >= 0 &&
1272 yyn <= YYTABLESIZE1116 && yycheck[yyn] == YYERRCODE256)
1273 {
1274#if YYDEBUG0
1275 if (yydebug)
1276 printf("%sdebug: state %d, error recovery shifting\
1277 to state %d\n", YYPREFIX"yy", *yyssp, yytable[yyn]);
1278#endif
1279 if (yyssp >= yysslim && yygrowstack())
1280 {
1281 goto yyoverflow;
1282 }
1283 *++yyssp = yystate = yytable[yyn];
1284 *++yyvsp = yylval;
1285 goto yyloop;
1286 }
1287 else
1288 {
1289#if YYDEBUG0
1290 if (yydebug)
1291 printf("%sdebug: error recovery discarding state %d\n",
1292 YYPREFIX"yy", *yyssp);
1293#endif
1294 if (yyssp <= yyss) goto yyabort;
1295 --yyssp;
1296 --yyvsp;
1297 }
1298 }
1299 }
1300 else
1301 {
1302 if (yychar == 0) goto yyabort;
1303#if YYDEBUG0
1304 if (yydebug)
1305 {
1306 yys = 0;
1307 if (yychar <= YYMAXTOKEN304) yys = yyname[yychar];
1308 if (!yys) yys = "illegal-symbol";
1309 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1310 YYPREFIX"yy", yystate, yychar, yys);
1311 }
1312#endif
1313 yychar = (-1);
1314 goto yyloop;
1315 }
1316yyreduce:
1317#if YYDEBUG0
1318 if (yydebug)
1319 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1320 YYPREFIX"yy", yystate, yyn, yyrule[yyn]);
1321#endif
1322 yym = yylen[yyn];
1323 if (yym
3.1
'yym' is 0
)
4
Taking false branch
22
Assuming 'yym' is 0
23
Taking false branch
1324 yyval = yyvsp[1-yym];
1325 else
1326 memset(&yyval, 0, sizeof yyval);
1327 switch (yyn)
5
'Default' branch taken. Execution continues on line 1984
24
Control jumps to 'case 50:' at line 1628
1328 {
1329case 3:
1330#line 177 "/usr/src/usr.bin/bc/bc.y"
1331{
1332 emit(yyvsp[-1].node, 0);
1333 macro_char = reset_macro_char;
1334 putchar('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
1335 free_tree();
1336 st_has_continue = false0;
1337 }
1338break;
1339case 4:
1340#line 185 "/usr/src/usr.bin/bc/bc.y"
1341{
1342 putchar('\n')(!__isthreaded ? __sputc('\n', (&__sF[1])) : (putc)('\n',
(&__sF[1])))
;
1343 free_tree();
1344 st_has_continue = false0;
1345 }
1346break;
1347case 5:
1348#line 191 "/usr/src/usr.bin/bc/bc.y"
1349{
1350 yyerrok(yyerrflag=0);
1351 }
1352break;
1353case 6:
1354#line 195 "/usr/src/usr.bin/bc/bc.y"
1355{
1356 yyerrok(yyerrflag=0);
1357 }
1358break;
1359case 7:
1360#line 201 "/usr/src/usr.bin/bc/bc.y"
1361{
1362 yyval.node = cs("");
1363 }
1364break;
1365case 9:
1366#line 206 "/usr/src/usr.bin/bc/bc.y"
1367{
1368 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1369 }
1370break;
1371case 11:
1372#line 213 "/usr/src/usr.bin/bc/bc.y"
1373{
1374 yyval.node = cs("");
1375 }
1376break;
1377case 14:
1378#line 219 "/usr/src/usr.bin/bc/bc.y"
1379{
1380 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1381 }
1382break;
1383case 16:
1384#line 224 "/usr/src/usr.bin/bc/bc.y"
1385{
1386 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1387 }
1388break;
1389case 17:
1390#line 231 "/usr/src/usr.bin/bc/bc.y"
1391{
1392 yyval.node = cs("");
1393 }
1394break;
1395case 19:
1396#line 238 "/usr/src/usr.bin/bc/bc.y"
1397{
1398 yyval.node = node(yyvsp[0].node, cs("ps."), END_NODE((ssize_t) -1));
1399 }
1400break;
1401case 20:
1402#line 242 "/usr/src/usr.bin/bc/bc.y"
1403{
1404 if (yyvsp[-1].str[0] == '\0')
1405 yyval.node = node(yyvsp[0].node, cs(yyvsp[-1].str), yyvsp[-2].lvalue.store,
1406 END_NODE((ssize_t) -1));
1407 else
1408 yyval.node = node(yyvsp[-2].lvalue.load, yyvsp[0].node, cs(yyvsp[-1].str), yyvsp[-2].lvalue.store,
1409 END_NODE((ssize_t) -1));
1410 }
1411break;
1412case 21:
1413#line 251 "/usr/src/usr.bin/bc/bc.y"
1414{
1415 yyval.node = node(cs("["), as(yyvsp[0].str),
1416 cs("]P"), END_NODE((ssize_t) -1));
1417 }
1418break;
1419case 22:
1420#line 256 "/usr/src/usr.bin/bc/bc.y"
1421{
1422 if (breaksp == 0) {
1423 warning("break not in for or while");
1424 YYERRORgoto yyerrlab;
1425 } else {
1426 yyval.node = node(
1427 numnode(nesting -
1428 breakstack[breaksp-1]),
1429 cs("Q"), END_NODE((ssize_t) -1));
1430 }
1431 }
1432break;
1433case 23:
1434#line 268 "/usr/src/usr.bin/bc/bc.y"
1435{
1436 if (breaksp == 0) {
1437 warning("continue not in for or while");
1438 YYERRORgoto yyerrlab;
1439 } else {
1440 st_has_continue = true1;
1441 yyval.node = node(numnode(nesting -
1442 breakstack[breaksp-1] - 1),
1443 cs("J"), END_NODE((ssize_t) -1));
1444 }
1445 }
1446break;
1447case 24:
1448#line 280 "/usr/src/usr.bin/bc/bc.y"
1449{
1450 sigset_t mask;
1451
1452 putchar('q')(!__isthreaded ? __sputc('q', (&__sF[1])) : (putc)('q', (
&__sF[1])))
;
1453 fflush(stdout(&__sF[1]));
1454 if (dc) {
1455 sigprocmask(SIG_BLOCK1, NULL((void *)0), &mask);
1456 sigsuspend(&mask);
1457 } else
1458 exit(0);
1459 }
1460break;
1461case 25:
1462#line 292 "/usr/src/usr.bin/bc/bc.y"
1463{
1464 if (nesting == 0) {
1465 warning("return must be in a function");
1466 YYERRORgoto yyerrlab;
1467 }
1468 yyval.node = yyvsp[0].node;
1469 }
1470break;
1471case 26:
1472#line 302 "/usr/src/usr.bin/bc/bc.y"
1473{
1474 ssize_t n;
1475
1476 if (st_has_continue)
1477 n = node(yyvsp[-1].node, cs("M"), yyvsp[-3].node, cs("s."),
1478 yyvsp[-5].node, yyvsp[-8].node, END_NODE((ssize_t) -1));
1479 else
1480 n = node(yyvsp[-1].node, yyvsp[-3].node, cs("s."), yyvsp[-5].node, yyvsp[-8].node,
1481 END_NODE((ssize_t) -1));
1482
1483 emit_macro(yyvsp[-8].node, n);
1484 yyval.node = node(yyvsp[-7].node, cs("s."), yyvsp[-5].node, yyvsp[-8].node, cs(" "),
1485 END_NODE((ssize_t) -1));
1486 }
1487break;
1488case 27:
1489#line 318 "/usr/src/usr.bin/bc/bc.y"
1490{
1491 emit_macro(yyvsp[-4].node, yyvsp[0].node);
1492 yyval.node = node(yyvsp[-2].node, yyvsp[-4].node, cs(" "), END_NODE((ssize_t) -1));
1493 }
1494break;
1495case 28:
1496#line 324 "/usr/src/usr.bin/bc/bc.y"
1497{
1498 emit_macro(yyvsp[-8].node, yyvsp[-4].node);
1499 emit_macro(yyvsp[-2].node, yyvsp[0].node);
1500 yyval.node = node(yyvsp[-6].node, yyvsp[-8].node, cs("e"), yyvsp[-2].node, cs(" "),
1501 END_NODE((ssize_t) -1));
1502 }
1503break;
1504case 29:
1505#line 332 "/usr/src/usr.bin/bc/bc.y"
1506{
1507 ssize_t n;
1508
1509 if (st_has_continue)
1510 n = node(yyvsp[-1].node, cs("M"), yyvsp[-3].node, yyvsp[-4].node, END_NODE((ssize_t) -1));
1511 else
1512 n = node(yyvsp[-1].node, yyvsp[-3].node, yyvsp[-4].node, END_NODE((ssize_t) -1));
1513 emit_macro(yyvsp[-4].node, n);
1514 yyval.node = node(yyvsp[-3].node, yyvsp[-4].node, cs(" "), END_NODE((ssize_t) -1));
1515 }
1516break;
1517case 30:
1518#line 343 "/usr/src/usr.bin/bc/bc.y"
1519{
1520 yyval.node = yyvsp[-1].node;
1521 }
1522break;
1523case 31:
1524#line 347 "/usr/src/usr.bin/bc/bc.y"
1525{
1526 yyval.node = yyvsp[0].node;
1527 }
1528break;
1529case 32:
1530#line 353 "/usr/src/usr.bin/bc/bc.y"
1531{
1532 yyval.node = cs(str_table[macro_char]);
1533 macro_char++;
1534 /* Do not use [, \ and ] */
1535 if (macro_char == '[')
1536 macro_char += 3;
1537 /* skip letters */
1538 else if (macro_char == 'a')
1539 macro_char = '{';
1540 else if (macro_char == ARRAY_CHAR0xa1)
1541 macro_char += 26;
1542 else if (macro_char == 255)
1543 fatal("program too big");
1544 if (breaksp == BREAKSTACK_SZ(sizeof(breakstack)/sizeof(breakstack[0])))
1545 fatal("nesting too deep");
1546 breakstack[breaksp++] = nesting++;
1547 }
1548break;
1549case 33:
1550#line 373 "/usr/src/usr.bin/bc/bc.y"
1551{
1552 breaksp--;
1553 }
1554break;
1555case 34:
1556#line 381 "/usr/src/usr.bin/bc/bc.y"
1557{
1558 int n = node(prologue, yyvsp[-1].node, epilogue,
1559 cs("0"), numnode(nesting),
1560 cs("Q"), END_NODE((ssize_t) -1));
1561 emit_macro(yyvsp[-8].node, n);
1562 reset_macro_char = macro_char;
1563 nesting = 0;
1564 breaksp = 0;
1565 }
1566break;
1567case 35:
1568#line 393 "/usr/src/usr.bin/bc/bc.y"
1569{
1570 yyval.node = function_node(yyvsp[-1].astr);
1571 free(yyvsp[-1].astr);
1572 prologue = cs("");
1573 epilogue = cs("");
1574 nesting = 1;
1575 breaksp = 0;
1576 breakstack[breaksp] = 0;
1577 }
1578break;
1579case 40:
1580#line 415 "/usr/src/usr.bin/bc/bc.y"
1581{
1582 add_par(letter_node(yyvsp[0].astr));
1583 free(yyvsp[0].astr);
1584 }
1585break;
1586case 41:
1587#line 420 "/usr/src/usr.bin/bc/bc.y"
1588{
1589 add_par(array_node(yyvsp[-2].astr));
1590 free(yyvsp[-2].astr);
1591 }
1592break;
1593case 42:
1594#line 425 "/usr/src/usr.bin/bc/bc.y"
1595{
1596 add_par(letter_node(yyvsp[0].astr));
1597 free(yyvsp[0].astr);
1598 }
1599break;
1600case 43:
1601#line 430 "/usr/src/usr.bin/bc/bc.y"
1602{
1603 add_par(array_node(yyvsp[-2].astr));
1604 free(yyvsp[-2].astr);
1605 }
1606break;
1607case 47:
1608#line 446 "/usr/src/usr.bin/bc/bc.y"
1609{
1610 add_local(letter_node(yyvsp[0].astr));
1611 free(yyvsp[0].astr);
1612 }
1613break;
1614case 48:
1615#line 451 "/usr/src/usr.bin/bc/bc.y"
1616{
1617 add_local(array_node(yyvsp[-2].astr));
1618 free(yyvsp[-2].astr);
1619 }
1620break;
1621case 49:
1622#line 456 "/usr/src/usr.bin/bc/bc.y"
1623{
1624 add_local(letter_node(yyvsp[0].astr));
1625 free(yyvsp[0].astr);
1626 }
1627break;
1628case 50:
1629#line 461 "/usr/src/usr.bin/bc/bc.y"
1630{
1631 add_local(array_node(yyvsp[-2].astr));
25
Calling 'array_node'
1632 free(yyvsp[-2].astr);
1633 }
1634break;
1635case 51:
1636#line 470 "/usr/src/usr.bin/bc/bc.y"
1637{
1638 yyval.node = cs("");
1639 }
1640break;
1641case 54:
1642#line 479 "/usr/src/usr.bin/bc/bc.y"
1643{
1644 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1645 }
1646break;
1647case 55:
1648#line 483 "/usr/src/usr.bin/bc/bc.y"
1649{
1650 yyval.node = node(yyvsp[-4].node, cs("l"), array_node(yyvsp[-2].astr),
1651 END_NODE((ssize_t) -1));
1652 free(yyvsp[-2].astr);
1653 }
1654break;
1655case 56:
1656#line 492 "/usr/src/usr.bin/bc/bc.y"
1657{
1658 yyval.node = cs(" 0 0=");
1659 }
1660break;
1661case 58:
1662#line 500 "/usr/src/usr.bin/bc/bc.y"
1663{
1664 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("="), END_NODE((ssize_t) -1));
1665 }
1666break;
1667case 59:
1668#line 504 "/usr/src/usr.bin/bc/bc.y"
1669{
1670 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("!="), END_NODE((ssize_t) -1));
1671 }
1672break;
1673case 60:
1674#line 508 "/usr/src/usr.bin/bc/bc.y"
1675{
1676 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs(">"), END_NODE((ssize_t) -1));
1677 }
1678break;
1679case 61:
1680#line 512 "/usr/src/usr.bin/bc/bc.y"
1681{
1682 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("!<"), END_NODE((ssize_t) -1));
1683 }
1684break;
1685case 62:
1686#line 516 "/usr/src/usr.bin/bc/bc.y"
1687{
1688 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("<"), END_NODE((ssize_t) -1));
1689 }
1690break;
1691case 63:
1692#line 520 "/usr/src/usr.bin/bc/bc.y"
1693{
1694 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("!>"), END_NODE((ssize_t) -1));
1695 }
1696break;
1697case 64:
1698#line 524 "/usr/src/usr.bin/bc/bc.y"
1699{
1700 yyval.node = node(yyvsp[0].node, cs(" 0!="), END_NODE((ssize_t) -1));
1701 }
1702break;
1703case 65:
1704#line 532 "/usr/src/usr.bin/bc/bc.y"
1705{
1706 yyval.node = node(cs("0"), epilogue,
1707 numnode(nesting), cs("Q"), END_NODE((ssize_t) -1));
1708 }
1709break;
1710case 66:
1711#line 537 "/usr/src/usr.bin/bc/bc.y"
1712{
1713 yyval.node = node(yyvsp[0].node, epilogue,
1714 numnode(nesting), cs("Q"), END_NODE((ssize_t) -1));
1715 }
1716break;
1717case 67:
1718#line 542 "/usr/src/usr.bin/bc/bc.y"
1719{
1720 yyval.node = node(cs("0"), epilogue,
1721 numnode(nesting), cs("Q"), END_NODE((ssize_t) -1));
1722 }
1723break;
1724case 68:
1725#line 550 "/usr/src/usr.bin/bc/bc.y"
1726{
1727 yyval.node = cs(" 0");
1728 }
1729break;
1730case 70:
1731#line 557 "/usr/src/usr.bin/bc/bc.y"
1732{
1733 yyval.node = node(yyvsp[0].lvalue.load, END_NODE((ssize_t) -1));
1734 }
1735break;
1736case 71:
1737#line 560 "/usr/src/usr.bin/bc/bc.y"
1738{
1739 yyval.node = node(cs("l."), END_NODE((ssize_t) -1));
1740 }
1741break;
1742case 72:
1743#line 564 "/usr/src/usr.bin/bc/bc.y"
1744{
1745 yyval.node = node(cs(" "), as(yyvsp[0].str), END_NODE((ssize_t) -1));
1746 }
1747break;
1748case 73:
1749#line 568 "/usr/src/usr.bin/bc/bc.y"
1750{
1751 yyval.node = yyvsp[-1].node;
1752 }
1753break;
1754case 74:
1755#line 572 "/usr/src/usr.bin/bc/bc.y"
1756{
1757 yyval.node = node(yyvsp[-1].node, cs("l"),
1758 function_node(yyvsp[-3].astr), cs("x"),
1759 END_NODE((ssize_t) -1));
1760 free(yyvsp[-3].astr);
1761 }
1762break;
1763case 75:
1764#line 579 "/usr/src/usr.bin/bc/bc.y"
1765{
1766 yyval.node = node(cs(" 0"), yyvsp[0].node, cs("-"),
1767 END_NODE((ssize_t) -1));
1768 }
1769break;
1770case 76:
1771#line 584 "/usr/src/usr.bin/bc/bc.y"
1772{
1773 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("+"), END_NODE((ssize_t) -1));
1774 }
1775break;
1776case 77:
1777#line 588 "/usr/src/usr.bin/bc/bc.y"
1778{
1779 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("-"), END_NODE((ssize_t) -1));
1780 }
1781break;
1782case 78:
1783#line 592 "/usr/src/usr.bin/bc/bc.y"
1784{
1785 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("*"), END_NODE((ssize_t) -1));
1786 }
1787break;
1788case 79:
1789#line 596 "/usr/src/usr.bin/bc/bc.y"
1790{
1791 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("/"), END_NODE((ssize_t) -1));
1792 }
1793break;
1794case 80:
1795#line 600 "/usr/src/usr.bin/bc/bc.y"
1796{
1797 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("%"), END_NODE((ssize_t) -1));
1798 }
1799break;
1800case 81:
1801#line 604 "/usr/src/usr.bin/bc/bc.y"
1802{
1803 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("^"), END_NODE((ssize_t) -1));
1804 }
1805break;
1806case 82:
1807#line 608 "/usr/src/usr.bin/bc/bc.y"
1808{
1809 yyval.node = node(yyvsp[0].lvalue.load, cs("1+d"), yyvsp[0].lvalue.store,
1810 END_NODE((ssize_t) -1));
1811 }
1812break;
1813case 83:
1814#line 613 "/usr/src/usr.bin/bc/bc.y"
1815{
1816 yyval.node = node(yyvsp[0].lvalue.load, cs("1-d"),
1817 yyvsp[0].lvalue.store, END_NODE((ssize_t) -1));
1818 }
1819break;
1820case 84:
1821#line 618 "/usr/src/usr.bin/bc/bc.y"
1822{
1823 yyval.node = node(yyvsp[-1].lvalue.load, cs("d1+"),
1824 yyvsp[-1].lvalue.store, END_NODE((ssize_t) -1));
1825 }
1826break;
1827case 85:
1828#line 623 "/usr/src/usr.bin/bc/bc.y"
1829{
1830 yyval.node = node(yyvsp[-1].lvalue.load, cs("d1-"),
1831 yyvsp[-1].lvalue.store, END_NODE((ssize_t) -1));
1832 }
1833break;
1834case 86:
1835#line 628 "/usr/src/usr.bin/bc/bc.y"
1836{
1837 if (yyvsp[-1].str[0] == '\0')
1838 yyval.node = node(yyvsp[0].node, cs(yyvsp[-1].str), cs("d"), yyvsp[-2].lvalue.store,
1839 END_NODE((ssize_t) -1));
1840 else
1841 yyval.node = node(yyvsp[-2].lvalue.load, yyvsp[0].node, cs(yyvsp[-1].str), cs("d"),
1842 yyvsp[-2].lvalue.store, END_NODE((ssize_t) -1));
1843 }
1844break;
1845case 87:
1846#line 637 "/usr/src/usr.bin/bc/bc.y"
1847{
1848 yyval.node = node(yyvsp[-1].node, cs("Z"), END_NODE((ssize_t) -1));
1849 }
1850break;
1851case 88:
1852#line 641 "/usr/src/usr.bin/bc/bc.y"
1853{
1854 yyval.node = node(yyvsp[-1].node, cs("v"), END_NODE((ssize_t) -1));
1855 }
1856break;
1857case 89:
1858#line 645 "/usr/src/usr.bin/bc/bc.y"
1859{
1860 yyval.node = node(yyvsp[-1].node, cs("X"), END_NODE((ssize_t) -1));
1861 }
1862break;
1863case 90:
1864#line 649 "/usr/src/usr.bin/bc/bc.y"
1865{
1866 yyval.node = node(yyvsp[0].node, cs("N"), END_NODE((ssize_t) -1));
1867 }
1868break;
1869case 91:
1870#line 653 "/usr/src/usr.bin/bc/bc.y"
1871{
1872 ssize_t n = node(cs("R"), yyvsp[0].node, END_NODE((ssize_t) -1));
1873 emit_macro(yyvsp[-2].node, n);
1874 yyval.node = node(yyvsp[-4].node, cs("d0!="), yyvsp[-2].node, END_NODE((ssize_t) -1));
1875 }
1876break;
1877case 92:
1878#line 659 "/usr/src/usr.bin/bc/bc.y"
1879{
1880 ssize_t n = node(cs("R"), yyvsp[0].node, END_NODE((ssize_t) -1));
1881 emit_macro(yyvsp[-2].node, n);
1882 yyval.node = node(yyvsp[-4].node, cs("d0="), yyvsp[-2].node, END_NODE((ssize_t) -1));
1883 }
1884break;
1885case 93:
1886#line 665 "/usr/src/usr.bin/bc/bc.y"
1887{
1888 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("G"), END_NODE((ssize_t) -1));
1889 }
1890break;
1891case 94:
1892#line 669 "/usr/src/usr.bin/bc/bc.y"
1893{
1894 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("GN"), END_NODE((ssize_t) -1));
1895 }
1896break;
1897case 95:
1898#line 673 "/usr/src/usr.bin/bc/bc.y"
1899{
1900 yyval.node = node(yyvsp[0].node, yyvsp[-2].node, cs("("), END_NODE((ssize_t) -1));
1901 }
1902break;
1903case 96:
1904#line 677 "/usr/src/usr.bin/bc/bc.y"
1905{
1906 yyval.node = node(yyvsp[0].node, yyvsp[-2].node, cs("{"), END_NODE((ssize_t) -1));
1907 }
1908break;
1909case 97:
1910#line 681 "/usr/src/usr.bin/bc/bc.y"
1911{
1912 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("("), END_NODE((ssize_t) -1));
1913 }
1914break;
1915case 98:
1916#line 685 "/usr/src/usr.bin/bc/bc.y"
1917{
1918 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, cs("{"), END_NODE((ssize_t) -1));
1919 }
1920break;
1921case 99:
1922#line 692 "/usr/src/usr.bin/bc/bc.y"
1923{
1924 yyval.lvalue.load = node(cs("l"), letter_node(yyvsp[0].astr),
1925 END_NODE((ssize_t) -1));
1926 yyval.lvalue.store = node(cs("s"), letter_node(yyvsp[0].astr),
1927 END_NODE((ssize_t) -1));
1928 free(yyvsp[0].astr);
1929 }
1930break;
1931case 100:
1932#line 700 "/usr/src/usr.bin/bc/bc.y"
1933{
1934 yyval.lvalue.load = node(yyvsp[-1].node, cs(";"),
1935 array_node(yyvsp[-3].astr), END_NODE((ssize_t) -1));
1936 yyval.lvalue.store = node(yyvsp[-1].node, cs(":"),
1937 array_node(yyvsp[-3].astr), END_NODE((ssize_t) -1));
1938 free(yyvsp[-3].astr);
1939 }
1940break;
1941case 101:
1942#line 708 "/usr/src/usr.bin/bc/bc.y"
1943{
1944 yyval.lvalue.load = cs("K");
1945 yyval.lvalue.store = cs("k");
1946 }
1947break;
1948case 102:
1949#line 713 "/usr/src/usr.bin/bc/bc.y"
1950{
1951 yyval.lvalue.load = cs("I");
1952 yyval.lvalue.store = cs("i");
1953 }
1954break;
1955case 103:
1956#line 718 "/usr/src/usr.bin/bc/bc.y"
1957{
1958 yyval.lvalue.load = cs("O");
1959 yyval.lvalue.store = cs("o");
1960 }
1961break;
1962case 105:
1963#line 727 "/usr/src/usr.bin/bc/bc.y"
1964{
1965 yyval.node = node(yyvsp[-2].node, yyvsp[0].node, END_NODE((ssize_t) -1));
1966 }
1967break;
1968case 106:
1969#line 733 "/usr/src/usr.bin/bc/bc.y"
1970{
1971 yyval.node = node(yyvsp[0].node, cs("ds.n"), END_NODE((ssize_t) -1));
1972 }
1973break;
1974case 107:
1975#line 737 "/usr/src/usr.bin/bc/bc.y"
1976{
1977 char *p = escape(yyvsp[0].str);
1978 yyval.node = node(cs("["), as(p), cs("]n"), END_NODE((ssize_t) -1));
1979 free(p);
1980 }
1981break;
1982#line 1975 "bc.c"
1983 }
1984 yyssp -= yym;
1985 yystate = *yyssp;
1986 yyvsp -= yym;
1987 yym = yylhs[yyn];
1988 if (yystate
5.1
'yystate' is equal to 0
== 0 && yym
5.2
'yym' is equal to 0
== 0)
6
Taking true branch
1989 {
1990#if YYDEBUG0
1991 if (yydebug)
1992 printf("%sdebug: after reduction, shifting from state 0 to\
1993 state %d\n", YYPREFIX"yy", YYFINAL1);
1994#endif
1995 yystate = YYFINAL1;
1996 *++yyssp = YYFINAL1;
1997 *++yyvsp = yyval;
1998 if (yychar
6.1
'yychar' is < 0
< 0)
7
Taking true branch
1999 {
2000 if ((yychar = yylex()) < 0) yychar = 0;
8
Assuming the condition is false
9
Taking false branch
2001#if YYDEBUG0
2002 if (yydebug)
2003 {
2004 yys = 0;
2005 if (yychar <= YYMAXTOKEN304) yys = yyname[yychar];
2006 if (!yys) yys = "illegal-symbol";
2007 printf("%sdebug: state %d, reading %d (%s)\n",
2008 YYPREFIX"yy", YYFINAL1, yychar, yys);
2009 }
2010#endif
2011 }
2012 if (yychar == 0) goto yyaccept;
10
Assuming 'yychar' is not equal to 0
11
Taking false branch
2013 goto yyloop;
12
Control jumps to line 1215
2014 }
2015 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
2016 yyn <= YYTABLESIZE1116 && yycheck[yyn] == yystate)
2017 yystate = yytable[yyn];
2018 else
2019 yystate = yydgoto[yym];
2020#if YYDEBUG0
2021 if (yydebug)
2022 printf("%sdebug: after reduction, shifting from state %d \
2023to state %d\n", YYPREFIX"yy", *yyssp, yystate);
2024#endif
2025 if (yyssp >= yysslim && yygrowstack())
2026 {
2027 goto yyoverflow;
2028 }
2029 *++yyssp = yystate;
2030 *++yyvsp = yyval;
2031 goto yyloop;
2032yyoverflow:
2033 yyerror("yacc stack overflow");
2034yyabort:
2035 if (yyss)
2036 free(yyss);
2037 if (yyvs)
2038 free(yyvs);
2039 yyss = yyssp = NULL((void *)0);
2040 yyvs = yyvsp = NULL((void *)0);
2041 yystacksize = 0;
2042 return (1);
2043yyaccept:
2044 if (yyss)
2045 free(yyss);
2046 if (yyvs)
2047 free(yyvs);
2048 yyss = yyssp = NULL((void *)0);
2049 yyvs = yyvsp = NULL((void *)0);
2050 yystacksize = 0;
2051 return (0);
2052}