lib/util: Count a trailing line that doesn't end in a newline
authorMartin Schwenke <martin@meltin.net>
Fri, 14 Dec 2018 03:43:57 +0000 (14:43 +1100)
committerKarolin Seeger <kseeger@samba.org>
Wed, 9 Jan 2019 08:37:19 +0000 (09:37 +0100)
commite7b344747eb7df22e91d857f40c8babf94665e97
treec38becbacb5d45f09599b6fb00a9ea25ee196972
parent55e8277a9751bbf00bc6ad6e5f12d9163ddbdf36
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