libutil/unescape: NULL terminate unescaped string

In commit 30fd43d7f3, unescape was
simplified significantly, but the new version failed to NULL terminate
the resulting string.

This causes bad behavior in various utilities, for example tr:

Broken:

  $ echo b2 | tr '\142' '\143'
  c3

Fixed:

  $ echo b2 | tr '\142' '\143'
  c2

This bug breaks libtool's usage of tr, causing gcc to fail to build with
sbase.
This commit is contained in:
Michael Forney 2017-03-07 23:10:48 -08:00 committed by Laslo Hunhold
parent 72b49a065b
commit fa0e5d6378

View File

@ -52,6 +52,7 @@ unescape(char *s)
eprintf("invalid escape sequence '\\%c'\n", *r);
}
}
*w = '\0';
return w - s;
}