Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#!/bin/sh

echo T.misc: miscellaneous buglets now watched for

awk=${awk-../a.out}

rm -f core

echo 'The big brown over the lazy doe
The big brown over the lazy dog
x
The big brown over the lazy dog' >foo
echo 'failed
succeeded
failed
succeeded' >foo1
$awk '{ if (match($0, /^The big brown over the lazy dog/) == 0) {
		printf("failed\n")
	} else {
		printf("succeeded\n")
	}
} ' foo >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc ghosh RE bug'

echo '123
1234567890
12345678901' >foo
echo '12345678901' >foo1
$awk 'length($0) > 10' foo >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc last number bug'

# check some \ sequences in strings (ascii)
echo HIJKL >foo1
echo foo | $awk '{ print "H\x49\x4a\x4BL" }' >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc hex string cvt'

echo 012x45 >foo1
$awk 'BEGIN { print "0\061\62x\0645" }' >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc oct string cvt'

# $i++ means ($i)++
echo 3 5 | $awk '{ i = 1; print $i++ ; print $1, i }' >foo1
echo '3
4 1' >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc bad field increment'

# makes sure that fields are recomputed even if self-assignment
# take into account that subtracting from NF now rebuilds the record
echo 'a b c
s p q r
x y z' >foo
echo 'a
s p
x' >foo1
$awk '{ NF -= 2; $1 = $1; print }' <foo >foo2
diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad field self-assignment"

echo '1
1' >foo1
$awk 'BEGIN {x = 1; print x; x = x; print x}' >foo2
diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad self-assignment"

echo 573109312 | $awk '{print $1*4}' >foo1
echo 2292437248 >foo2
diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad overflow"

# note that there are 8-bit characters in the echo
# some shells will probably screw this up.
echo '#
code € 1
code € 2' |
$awk '/^#/' >foo1
echo '#' >foo2
diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad match of 8-bit char"

echo hello |
$awk 'BEGIN	{ FILENAME = "/etc/passwd" }
	{ print $0 }' >/dev/null
if test -r core; then echo 1>&2 "BAD: T.misc /etc/passwd dropped core"; fi

echo hello |
$awk '  function foo(foo) {
                foo = 1
                foo()
        }
	{ foo(bar) }
' >/dev/null 2>&1
if test -r core; then
	echo 1>&2 "BAD: T.misc function foo(foo) dropped core"
	rm -f core
fi

echo '2
10' |
$awk '{ x[NR] = $0 }	# test whether $0 is NUM as well as STR
END { if (x[1] > x[2]) print "BAD: T.misc: $0 is not NUM" }'


$awk 'BEGIN {
	npad = substr("alexander" "           ",1,15)
	print npad
	}' >foo
grep '\\' foo && echo 1>&2 "BAD: T.misc alexander fails"

# This should give an error about function arguments
$awk '
function foo(x) { print "x is" x }
BEGIN { foo(foo) }
' 2>foo
grep "can't use function foo" foo >/dev/null || echo 1>&2 "BAD: T.misc fcn args"


# gawk defref test; should give error about undefined function
$awk 'BEGIN { foo() }' 2>foo
grep "calling undefined function foo" foo >/dev/null || echo 1>&2 "BAD: T.misc undefined function"


# gawk arrayparm test; should give error about function 
$awk '
BEGIN {
    foo[1]=1;
    foo[2]=2;
    bug1(foo);
}
function bug1(i) {
    for (i in foo) {
	bug2(i);
	delete foo[i];
	print i,1,bot[1];
    }
}
function bug2(arg) {
    bot[arg]=arg;
}
' 2>foo
grep "can.t assign to foo" foo >/dev/null || echo 1>&2 "BAD: T.misc foo bug"


# This should be a syntax error
$awk '
!x = y
' 2>foo
grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error !x=y fails"

# This should print bbb
$awk '
BEGIN { up[1] = "a"
	for (i in up) gsub("a", "A", x)
	print x x "bbb"
	exit
      }
' >foo
grep bbb foo >/dev/null || echo 1>&2 "BAD: T.misc gsub failed"

echo yes |
$awk '
BEGIN {
	printf "push return" >"/dev/null"
	getline ans <"/dev/null"
} '
if test -r core; then echo 1>&2 "BAD: T.misc getline ans dropped core"; fi

$awk 'BEGIN { unireghf() }
function unireghf(hfeed) { hfeed[1] = 0 }'
if test -r core; then echo 1>&2 "BAD: T.misc unireghf dropped core"; fi

echo x | $awk '/[/]/' 2>foo
grep 'nonterminated character class' foo >/dev/null || error 'BAD: T.misc nonterminated fails'
if test -r core; then echo 1>&2 "BAD: T.misc nonterminated dropped core"; fi

$awk '
function f() { return 12345 }
BEGIN { printf "<%s>\n", f() }
' >foo
grep '<12345>' foo >/dev/null || echo 'BAD: T.misc <12345> fails'

echo 'abc
def

ghi
jkl' >foo
$awk '
BEGIN {	RS = ""
	while (getline <"foo")
		print
}' >foo1
$awk 'END {print NR}' foo1 | grep 4 >/dev/null || echo 'BAD: T.misc abcdef fails'


# The following should not produce a warning about changing a constant
# nor about a curdled tempcell list
$awk 'function f(x) { x = 2 }
BEGIN { f(1) }' >foo
grep '^' foo && echo 'BAD: test constant change fails'

# The following should not produce a warning about a curdled tempcell list
$awk 'function f(x) { x }
BEGIN { f(1) }' >foo
grep '^' foo && echo 'BAD: test tempcell list fails'

$awk 'BEGIN { print 9, a=10, 11; print a; exit }' >foo1
echo '9 10 11
10' >foo2
diff foo1 foo2 || echo 'BAD: T.misc (embedded expression)'

echo "abc defgh ijkl" | $awk '
  { $1 = ""; line = $0; print line; print $0; $0 = line; print $0 }' >foo1
echo " defgh ijkl
 defgh ijkl
 defgh ijkl" >foo2
diff foo1 foo2 || echo 'BAD: T.misc (assignment to $0)'

$awk '
function min(a, b)
{
	if (a < b)
		return a
	else
		return b
}
BEGIN { exit }
'
if test -r core; then echo 1>&2 "BAD: T.misc function min dropped core"; fi

# The following should not give a syntax error message:
$awk '
function expand(chart) {
	getline chart < "CHAR.ticks"
}
' >foo
grep '^' foo >/dev/null && echo 'BAD: T.misc expand error'

$awk 'BEGIN { print 1e40 }' >/dev/null
if test -r core; then echo 1>&2 "BAD: T.misc 1E40 dropped core"; fi

# The following syntax error should not dump core:
$awk '
$NF==3	{first=1}
$NF==2 && first==0 && (abs($1-o1)>120||abs($2-o2)>120)	{print $0}
$NF==2	{o1=%1; o2=$2; first=0}
' 2>/dev/null
if test -r core; then echo 1>&2 "BAD: T.misc first/abs dropped core"; fi

# The following syntax error should not dump core:
$awk '{ n = split($1, address, !); print address[1] }' 2>foo
grep 'illegal statement' foo >/dev/null || echo 'BAD: T.misc split error'
if test -r core; then echo 1>&2 "BAD: T.misc split! dropped core"; fi

# The following should cause a syntax error message
$awk 'BEGIN {"hello"}' 2>foo
grep 'illegal statement' foo >/dev/null || echo 'BAD: T.misc hello error'

# The following should give a syntax error message:
$awk '
function pile(c,     r) {
	r = ++pile[c]
}

{ pile($1) }
' 2>foo
grep 'context is' foo >/dev/null || echo 'BAD: T.misc pile error'

# This should complain about missing atan2 argument:
$awk 'BEGIN { atan2(1) }' 2>foo
grep 'requires two arg' foo >/dev/null || echo 'BAD: T.misc atan2 error'

# This should not core dump:
$awk 'BEGIN { f() }
function f(A) { delete A[1] }
'
if test -r core; then echo 1>&2 "BAD: T.misc delete dropped core"; fi

# nasty one:  should not be able to overwrite constants
$awk 'BEGIN { gsub(/ana/,"anda","banana")
		printf "the monkey ate a %s\n", "banana" }
' >/dev/null 2>foo
grep 'syntax error' foo >/dev/null || echo 'BAD: T.misc gsub banana error'

# nasty one:  should not be able to overwrite constants
$awk 'BEGIN { sub(/ana/,"anda","banana")
		printf "the monkey ate a %s\n", "banana" }
' >/dev/null 2>foo
grep 'syntax error' foo >/dev/null || echo 'BAD: T.misc sub banana error'

# line numbers used to double-count comments
$awk '#
#
#
/x
' >/dev/null 2>foo
grep 'line [45]' foo >/dev/null || echo 'BAD: T.misc lineno'

echo 'x
\y' >foo1
$awk 'BEGIN { print "x\f\r\b\v\a\\y" }' >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc weird chars'

echo 0 >foo1
$awk '	BEGIN { exit }
	{ print }
	END { print NR }' >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc BEGIN exit'

echo 1 >foo1
$awk '	{ exit }
	END { print NR }' /etc/passwd >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit'

echo 1 >foo1
$awk '	{i = 1; while (i <= NF) {if (i == NF) exit; i++ } }
	END { print NR }' /etc/passwd >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 2'

echo 1 >foo1
$awk '	function f() {
		i = 1; while (i <= NF) {if (i == NF) return NR; i++ }
	}
	{ if (f() == 1) exit }
	END { print NR }' /etc/passwd >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc while return'

echo 1 >foo1
$awk '	function f() {
		split("a b c", arr)
		for (i in arr) {if (i == 3) return NR; i++ }
	}
	{ if (f() == 1) exit }
	END { print NR }' /etc/passwd >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc while return'

echo 1 >foo1
$awk '	{i = 1; do { if (i == NF) exit; i++ } while (i <= NF) }
	END { print NR }' /etc/passwd >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 3'

echo 1 >foo1
$awk '	function f() {
		i = 1; do { if (i == NF) return NR; i++ } while (i <= NF)
	}
	{ if (f() == 1) exit }
	END { print NR }' /etc/passwd >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc do return'

echo 1 >foo1
$awk '	{i = 1; do { if (i == NF) break; i++ } while (i <= NF); exit }
	END { print NR }' /etc/passwd >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 4'

echo 1 >foo1
$awk '	{ n = split($0, x)
	  for (i in x) {
	 	if (i == 1)
			exit } }
	END { print NR }' /etc/passwd >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 5'

echo XXXXXXXX >foo1
$awk 'BEGIN { s = "ab\fc\rd\be"
	t = s; 	gsub("[" s "]", "X", t); print t }' >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc weird escapes in char class'

$awk '{}' /etc/passwd glop/glop >foo 2>foo2
grep "can't open.*glop" foo2 >/dev/null || echo "BAD: T.misc can't open"

echo '


a
aa

b


c

' >foo
echo 3 >foo1
$awk 'BEGIN { RS = "" }; END { print NR }' foo >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc RS botch'

$awk 'BEGIN \
	{
		print "hello, world"
	}
}}}' >foo1 2>foo2
grep 'source line 4' foo2 >/dev/null 2>&1 || echo 'BAD: T.misc continuation line number'


echo 111 222 333 >foo
$awk '{ f[1]=1; f[2]=2; print $f[1], $f[1]++, $f[2], f[1], f[2] }' foo >foo2
echo 111 111 222 2 2 >foo1
cmp -s foo1 foo2 || echo 'BAD: T.misc $f[1]++'


# These should be syntax errors
$awk . 2>foo
grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error . fails"

$awk .. 2>foo
grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error .. fails"

$awk .E. 2>foo
grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error .E. fails"

$awk .++. 2>foo
grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error .++. fails"



# These should be syntax errors
$awk '$' 2>foo
grep "unexpected" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error $ fails"

$awk '{print $' 2>foo
grep "unexpected" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error $2 fails"

$awk '"' 2>foo
grep "non-terminated" foo >/dev/null || echo 1>&2 "BAD: T.misc bare quote fails"


# %c of 0 is explicit null byte

./echo '3' >foo1
$awk 'BEGIN {printf("%c%c\n", 0, 0) }' | wc | $awk '{print $3}' >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc null byte'

# non-terminated RE

$awk /xyz >foo 2>&1
grep "non-terminated" foo >/dev/null || echo 1>&2 "BAD: T.misc non-terminated RE"

# next several were infinite loops, found by brian tsang.
# this is his example:

$awk 'BEGIN {
    switch (substr("x",1,1)) {
    case /ask.com/:
	break
    case "google":
	break
    }
}' >foo 2>&1
grep "illegal statement" foo >/dev/null || echo 1>&2 "BAD: T.misc looping syntax error 1"

$awk 'BEGIN { s { c /./ } }' >foo 2>&1
grep "illegal statement" foo >/dev/null || echo 1>&2 "BAD: T.misc looping syntax error 2"

$awk 'BEGIN { s { c /../ } }' >foo 2>&1
grep "illegal statement" foo >/dev/null || echo 1>&2 "BAD: T.misc looping syntax error 3"

$awk 'BEGIN {printf "%2$s %1$s\n", "a", "b"}' >foo 2>&1
grep "'$' not permitted in awk formats" foo >/dev/null || echo 1>&2 "BAD: T.misc '$' not permitted in formats"

echo 'a
b c
de fg hi' >foo0
$awk 'END { print NF, $0 }' foo0 >foo1
awk '{ print NF, $0 }' foo0| tail -1 >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc END must preserve $0'

echo 'fg hi' >foo0
$awk 'END { print NF, $0 }' foo0 >foo1
awk '{ print NF, $0 }' foo0| tail -1 >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc END must preserve $0'

echo '' >foo0
$awk 'END { print NF, $0 }' foo0 >foo1
awk '{ print NF, $0 }' foo0| tail -1 >foo2
cmp -s foo1 foo2 || echo 'BAD: T.misc END must preserve $0'

# Check for nonzero exit status on I/O error.
echo 'E 2' >foo1
(trap '' PIPE; "$awk" 'BEGIN { print "hi"; }' 2>/dev/null; echo "E $?" >foo2) | :
cmp -s foo1 foo2 || echo 'BAD: T.misc exit status on I/O error'