bin/136383: [PATCH] usr.bin/jot fix usage of uninitialized values
Ulrich Spoerlein
uqs at spoerlein.net
Mon Jul 6 16:20:04 UTC 2009
>Number: 136383
>Category: bin
>Synopsis: [PATCH] usr.bin/jot fix usage of uninitialized values
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon Jul 06 16:20:01 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator: Ulrich Spörlein
>Release: FreeBSD 7.2-STABLE i386
>Organization:
>Environment:
>Description:
A run of clang's static analyzer found that jot(1) has a bug regarding
the use of uninitialized variables.
https://www.spoerlein.net/scan-build/2009-07-04-1/report-BcTTXG.html#EndPath
The repetitions, start, end and step values are not preset. When defaults
are given, it will use "random" values for these.
>How-To-Repeat:
% jot -
0
0
% jot - -
0
0
0
% jot - - -
0
0
0
0
% jot - - - -
0
0
0
0
0
>Fix:
Simply pre-set all four variables to their defaults to match behaviour
claimed in manpage. Also add regression test for this case.
--- jot.diff begins here ---
Index: tools/regression/usr.bin/jot/regress.sh
===================================================================
--- tools/regression/usr.bin/jot/regress.sh (revision 193930)
+++ tools/regression/usr.bin/jot/regress.sh (working copy)
@@ -1,6 +1,6 @@
# $FreeBSD$
-echo 1..56
+echo 1..57
REGRESSION_START($1)
@@ -20,6 +20,7 @@
REGRESSION_TEST(`ddhh', `jot - - 120 2')
REGRESSION_TEST(`ddhd', `jot - - 120 -')
REGRESSION_TEST(`dddh', `jot - - - 2')
+REGRESSION_TEST(`dddd', `jot - - - -')
REGRESSION_TEST(`hhhh2', `jot 30 20 160 2')
REGRESSION_TEST(`hhhd2', `jot 30 20 160 -')
REGRESSION_TEST(`hhdh2', `jot 30 20 - 2')
Index: tools/regression/usr.bin/jot/regress.dddd.out
===================================================================
--- tools/regression/usr.bin/jot/regress.dddd.out (revision 0)
+++ tools/regression/usr.bin/jot/regress.dddd.out (revision 0)
@@ -0,0 +1,100 @@
+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
Index: usr.bin/jot/jot.c
===================================================================
--- usr.bin/jot/jot.c (revision 193930)
+++ usr.bin/jot/jot.c (working copy)
@@ -101,13 +101,13 @@
int ch;
int mask = 0;
int n = 0;
- double begin;
+ double begin = BEGIN_DEF;
double divisor;
- double ender;
- double s;
+ double ender = ENDER_DEF;
+ double s = STEP_DEF;
double x, y;
long i;
- long reps;
+ long reps = REPS_DEF;
while ((ch = getopt(argc, argv, "b:cnp:rs:w:")) != -1)
switch (ch) {
--- jot.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list