#
301917 |
|
15-Jun-2016 |
truckman |
MFC r299484, r301574
r299484 | cem | 2016-05-11 15:04:28 -0700 (Wed, 11 May 2016) | 13 lines
random(6): Fix double-close
In the case where a file lacks a trailing newline, there is some "evil" code to reverse goto the tokenizing code ("make_token") for the final token in the file. In this case, 'fd' is closed more than once. Use a negative sentinel value to guard close(2), preventing the double close.
Ideally, this code would be restructured to avoid this ugly construction.
r301574 | truckman | 2016-06-07 19:14:05 -0700 (Tue, 07 Jun 2016) | 15 lines
Fix a (false positive?) Argument cannot be negative coverity defect.
Rather than guarding close(fd) with an fd >= 0 test and setting fd to -1 when it is closed to avoid a potential double-close, just move the close() call after the conditional "goto make_token". This moves the close() call totally outside the loop to avoid the possibility of calling it twice. This should also prevent a Coverity warning about checking fd for validity after it was previously passed to read().
Reported by: Coverity CID: 1006123, 1355335
|
#
256281 |
|
10-Oct-2013 |
gjb |
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
Approved by: re (implicit) Sponsored by: The FreeBSD Foundation |
#
241847 |
|
22-Oct-2012 |
eadler |
Free buf when its no longer used. This helps eliminate a static analysis warning.
PR: ports/172566 Submitted by: Erik Cederstrand <erik@cederstrand.dk> Approved by: cperciva MFC after: 3 days
|
#
209157 |
|
14-Jun-2010 |
uqs |
random(6): avoid dead assignments
Found by: clang static analyzer
|
#
181615 |
|
11-Aug-2008 |
ache |
Suggections from bde@ 1) Split too long source lines 2) Portable code should not assume that null pointer == all-bits-0, so back out prev. calloc() change.
Submitted by: bde
|
#
181527 |
|
10-Aug-2008 |
ache |
All cosmetic. 1) Rename RANDOM_MAX to RANDOM_MAX_PLUS1 to not confuse with random()'s max 2) Use calloc() instead of zeroing fields explicitly 3) "too many lines" -> "too many delimiters" for err()
|
#
181412 |
|
08-Aug-2008 |
ache |
1) Fix longstanding math bug with denominator > 1 (wrong probability). Test case: random -f some_small_file 10000 (in most cases must be no output) 2) Prevent number of lines > RANDOM_MAX (overflow or nothing may be choosed) with EFBIG err() 3) After line is found, terminate list loop for -U case too, since nothing to do in the rest of the loop left.
|
#
181410 |
|
07-Aug-2008 |
ache |
I was confused a bit by the wrong construction with RAND_MAX used in randomize_fd.c. Although the max value is the same currently, RAND_MAX is for rand(), not for random(). So move RANDOM_MAX const to the common file now, make it UL and use in randomize_fd.c too. (in any case its old value was 1 less then must be, as noted in the prev. commit)
|
#
157758 |
|
14-Apr-2006 |
ache |
1) Fix hang at the end of line buffer (PR 95715) 2) Localize
PR: 95715 Submitted by: Li-Lun Wang <llwang@infor.org> (slightly edited by me)
|
#
110928 |
|
15-Feb-2003 |
seanc |
flexlint rears its head as well as some style(9) fixes[1]. Fixed a few bugs for a few corner cases and correctly handle the case where read(2) is read()'ing from a non-file descriptor and could get fewer bytes back than the buffer, but it isn't EOF[2]. random(6) extensively tested and believed to be bug free (save performance for large files).
Submitted by: mkm [1], tjr[2]
|
#
110723 |
|
11-Feb-2003 |
seanc |
Update random(6) to have the ability to randomize a file/stdin based off of lines or words. See the man page for details.
Reviewed by: markm MFC after: 3 days
|