The length set by fgetln is always the length of the line ending at the
newline character, while the length set by getline includes the null
byte and any extra bytes that may be allocated for the buffer. Change
the getline calls that were converted from fgetln to use the return
value of getline in place of the buffer length parameter.
Update the example code in DIFFERENCES to separate the line length and
buffer length variables.
Tested this against tag v13.2: xargs -p is only looking for y/n so this doesn't change much there other than fixing the uninitialized buffer, and I couldn't get cut to actually fail, but this definitely makes a difference with join and head:
for example, for join, running echo '1,one' > file-1 ; echo '1,uno' > file-2 ; join -t, file-1 file-2
before, results in:
1,one
,uno
and after:
1,one,uno
for head, tested with echo line1 > test-file ; echo line2 >> test-file ; head -1 test-file | xxd
before:
00000000: 6c69 6e65 310a 0000 0000 0000 0000 0000 line1...........
00000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 ........
after:
00000000: 6c69 6e65 310a line1.
The length set by fgetln is always the length of the line ending at the
newline character, while the length set by getline includes the null
byte and any extra bytes that may be allocated for the buffer. Change
the getline calls that were converted from fgetln to use the return
value of getline in place of the buffer length parameter.
Update the example code in DIFFERENCES to separate the line length and
buffer length variables.
Tested this against tag v13.2: `xargs -p` is only looking for y/n so this doesn't change much there other than fixing the uninitialized buffer, and I couldn't get `cut` to actually fail, but this definitely makes a difference with `join` and `head`:
for example, for join, running `echo '1,one' > file-1 ; echo '1,uno' > file-2 ; join -t, file-1 file-2`
before, results in:
```
1,one
,uno
```
and after:
```
1,one,uno
```
for head, tested with `echo line1 > test-file ; echo line2 >> test-file ; head -1 test-file | xxd`
before:
```
00000000: 6c69 6e65 310a 0000 0000 0000 0000 0000 line1...........
00000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 ........
```
after:
```
00000000: 6c69 6e65 310a line1.
```