Fix a section() bug.

Turns out that awk's indexes are documented to start from 1;
So what happens if you use 0? Apparently it's undefined behavior, so
substr(var, 0, 5);
and
substr(var, 1, 5);
May or may not actually do the same thing. In Debian 6, the former
doesn't quite work, and actually returns something like substr(var, 1, 4),
which broke section()'s output.
This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-04-03 10:55:51 -03:00
parent c0dedd19bf
commit 12bd26022a
3 changed files with 3 additions and 3 deletions

View File

@@ -560,7 +560,7 @@ section () {
i = index($0, "_");
x = substr($0, i);
gsub(/[_ \t]/, "#", x);
printf("%s%s\n", substr($0, 0, i-1), x);
printf("%s%s\n", substr($0, 1, i-1), x);
}')"
printf "%s\n" "${line}"
}

View File

@@ -697,7 +697,7 @@ section () {
i = index($0, "_");
x = substr($0, i);
gsub(/[_ \t]/, "#", x);
printf("%s%s\n", substr($0, 0, i-1), x);
printf("%s%s\n", substr($0, 1, i-1), x);
}')"
printf "%s\n" "${line}"
}