lib/util: Count a trailing line that doesn't end in a newline
commitdaac354298349ca373ccc62b12c86df114c904e0
authorMartin Schwenke <martin@meltin.net>
Fri, 14 Dec 2018 03:43:57 +0000 (14 14:43 +1100)
committerKarolin Seeger <kseeger@samba.org>
Wed, 9 Jan 2019 09:13:14 +0000 (9 10:13 +0100)
tree4c78260329e917f8c73f97b80d71cd4e51c5e817
parent5067926e4fe7fce7790243bb938677d0c4182edb
lib/util: Count a trailing line that doesn't end in a newline

If the final line of a file does not contain a newline then it isn't
included in the line count.

Change i to point to the next slot in the array instead of the current
one.  This means that that the current line won't be thrown away if no
newline is seen.

Without changing i to unsigned int, the -O3 --picky -developer build
fails with:

[ 745/4136] Compiling lib/util/util_file.c

==> /builds/samba-team/devel/samba/samba-o3.stderr <==
../../lib/util/util_file.c: In function ‘file_lines_parse’:
../../lib/util/util_file.c:251:8: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
  while (i > 0 && ret[i-1][0] == 0) {
        ^
cc1: all warnings being treated as errors

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13717

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Wed Dec 19 08:08:28 CET 2018 on sn-devel-144

(cherry picked from commit 5118985841aa0363147d552f243ab5a7d90dbdaf)
lib/util/tests/file.c
lib/util/util_file.c