diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-09-01 22:42:07 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-09-01 22:42:07 +0300 |
commit | bfc794de222760871c6c6de6bb923a0bf57ee166 (patch) | |
tree | 4c58b3a49e2ab2feed1ebd39584663236d70c8d2 | |
parent | 00f86a1d837f838a715dc879076325f772c4c5c9 (diff) | |
download | gawk-bfc794de222760871c6c6de6bb923a0bf57ee166.tar.gz |
Minor improvement to substr().
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | builtin.c | 13 |
2 files changed, 16 insertions, 3 deletions
@@ -1,3 +1,9 @@ +2014-09-01 Arnold D. Robbins <arnold@skeeve.com> + + * builtin.c (do_substr): Return "" instead of null string in case + result is passed to length() with --lint. Based on discussions in + comp.lang.awk. + 2014-08-27 Arnold D. Robbins <arnold@skeeve.com> * configure.ac: Add test for strcasecmp. @@ -1759,7 +1759,14 @@ do_substr(int nargs) else if (do_lint == DO_LINT_INVALID && ! (d_length >= 0)) lintwarn(_("substr: length %g is not >= 0"), d_length); DEREF(t1); - return dupnode(Nnull_string); + /* + * Return explicit null string instead of doing + * dupnode(Nnull_string) so that if the result + * is checked with the combination of length() + * and lint, no error is reported about using + * an uninitialized value. Same thing later, too. + */ + return make_string("", 0); } if (do_lint) { if (double_to_int(d_length) != d_length) @@ -1813,7 +1820,7 @@ do_substr(int nargs) if (do_lint && (do_lint == DO_LINT_ALL || ((indx | length) != 0))) lintwarn(_("substr: source string is zero length")); DEREF(t1); - return dupnode(Nnull_string); + return make_string("", 0); } /* get total len of input string, for following checks */ @@ -1830,7 +1837,7 @@ do_substr(int nargs) lintwarn(_("substr: start index %g is past end of string"), d_index); DEREF(t1); - return dupnode(Nnull_string); + return make_string("", 0); } if (length > src_len - indx) { if (do_lint) |