summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Layton <jlayton@kernel.org>2019-06-13 10:55:35 -0400
committerAndreas Gruenbacher <agruenba@redhat.com>2019-06-13 22:37:26 +0200
commit2ad8924413eeb8a2123eccccef4371342d19d6e4 (patch)
tree25cb1769170601cae66eeffc47e9bf35c96a7f44
parentcb4786f1b6eb694545541bef89f942b00c2ff022 (diff)
downloadattr-2ad8924413eeb8a2123eccccef4371342d19d6e4.tar.gz
getfattr: don't count terminating NULL in well_enough_printable
If the value is a string with the terminating NUL included in the length, then don't count that terminating NUL when determining whether the string is printable. This is consistent with the fact that getfattr doesn't print the terminating NUL character in --encoding=text (commit 7fed4441e12d). Signed-off-by: Jeff Layton <jlayton@kernel.org>
-rw-r--r--tools/getfattr.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/getfattr.c b/tools/getfattr.c
index 72a8852..0ba5781 100644
--- a/tools/getfattr.c
+++ b/tools/getfattr.c
@@ -110,6 +110,10 @@ int well_enough_printable(const char *value, size_t size)
{
size_t n, nonpr = 0;
+ /* Don't count the NULL terminator if there is one */
+ if (size && !value[size - 1])
+ size--;
+
for (n=0; n < size; n++)
if (!isprint(*value++))
nonpr++;