Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Feb 2019 22:25:34 +0000
From:      bugzilla-noreply@freebsd.org
To:        pkg@FreeBSD.org
Subject:   maintainer-feedback requested: [Bug 236093] ports-mgmt/pkg: possible error in function format_rate_SI (src/event.c)
Message-ID:  <bug-236093-32340-MFJjXG8jT1@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-236093-32340@https.bugs.freebsd.org/bugzilla/>
References:  <bug-236093-32340@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
Bugzilla Automation <bugzilla@FreeBSD.org> has asked freebsd-pkg mailing li=
st
<pkg@FreeBSD.org> for maintainer-feedback:
Bug 236093: ports-mgmt/pkg: possible error in function format_rate_SI
(src/event.c)
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D236093



--- Description ---
src/event.c:

87 /* units for format_size */=09=09=09=09=09=09=20=20=20=20=20=20=20

88 static const char *unit_SI[] =3D { " ", "k", "M", "G", "T", };

109 static void=20=09=09=09=09=09=09=09=20=20=20=20=20=20=20

110 format_rate_SI(char *buf, int size, off_t bytes)=09=09=09=20=20=20=20=
=20=20=20

111 {=09=09=09=09=09=09=09=09=09=20=20=20=20=20=20=20

112	    int i;=09=09=09=09=09=09=09=20=20=20=20=20=20=20

113=09=09=09=09=09=09=09=09=09=20=20=20=20=20=20=20

114	    bytes *=3D 100;=09=09=09=09=09=09=20=20=20=20=20=20=20

115	    for (i =3D 0; bytes >=3D 100*1000 && unit_SI[i][0] !=3D 'T'; i++)=
=20=20=20=20=20=20=20=20

116		    bytes =3D (bytes + 500) / 1000;=09=09=09=20=20=20=20=20=20=20

117	    if (i =3D=3D 0) {=09=09=09=09=09=09=20=20=20=20=20=20=20

118		    i++;=09=09=09=09=09=09=20=20=20=20=20=20=20

119		    bytes =3D (bytes + 500) / 1000;=09=09=09=20=20=20=20=20=20=20

120	    }=09=09=09=09=09=09=09=09=20=20=20=20=20=20=20

121	    snprintf(buf, size, "%3lld.%1lld%s%s",=09=09=09=20=20=20=20=20=20=20

122		(long long) (bytes + 5) / 100,=09=09=09=09=20=20=20=20=20=20=20

123		(long long) (bytes + 5) / 10 % 10,=09=09=09=20=20=20=20=20=20=20

124		unit_SI[i],=09=09=09=09=09=09=20=20=20=20=20=20=20

125		i ? "B" : " ");=20=09=09=09=09=09=20=20=20=20=20=20=20

126 }

Unless I am mistaken, i can not be zero at lines 124-125. As a consequence:

=E2=80=A2 the first element of unit_SI is never used
=E2=80=A2 in the call to snprintf, the last argument is always "B", never "=
 "



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-236093-32340-MFJjXG8jT1>