misc: Avoid UTF-8 in error messages
PATCH 1/1 misc: Avoid UTF-8 in error messages
While most developers are now using UTF-8 environments, it's harder to guarantee that error messages will be output to a multibyte locale. Rather than risking error messages that get corrupted into mojibake when the user runs qemu in a non-multibyte locale, let's stick to straight ASCII error messages, rather than assuming that our use of UTF-8 in source code string constants will work unchanged in other locales.
--- hw/misc/tmp105.c | 2 +- hw/misc/tmp421.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/misc/tmp105.c +1 -1
@@ -79,7 +79,7 @@ static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,return ; }if (temp >=128000 || temp <-128000 ) { -error_setg (errp,"value %" PRId64".%03" PRIu64" °C is out of range" , +error_setg (errp,"value %" PRId64".%03" PRIu64" C is out of range" , temp /1000 , temp %1000 );return ; }
hw/misc/tmp421.c +1 -1
@@ -153,7 +153,7 @@ static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name, }if (temp >= maxs[ext_range] || temp < mins[ext_range]) { -error_setg (errp,"value %" PRId64".%03" PRIu64" °C is out of range" , +error_setg (errp,"value %" PRId64".%03" PRIu64" C is out of range" , temp /1000 , temp %1000 );return ; }
Signature · 1 line
2.17.2
Quoted 34 lines · Eric Blake
While most developers are now using UTF-8 environments, it's harder to guarantee that error messages will be output to a multibyte locale. Rather than risking error messages that get corrupted into mojibake when the user runs qemu in a non-multibyte locale, let's stick to straight ASCII error messages, rather than assuming that our use of UTF-8 in source code string constants will work unchanged in other locales.
Reported-by Markus Armbruster <[email protected]>Signed-off-by Eric Blake <[email protected]>--- hw/misc/tmp105.c | 2 +- hw/misc/tmp421.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/misc/tmp105.c +1
-1@@ -79,7 +79,7 @@ static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,return ; }if (temp >=128000 || temp <-128000 ) { -error_setg (errp,"value %" PRId64".%03" PRIu64" °C is out of range" , +error_setg (errp,"value %" PRId64".%03" PRIu64" C is out of range" , temp /1000 , temp %1000 );return ; }hw/misc/tmp421.c +0
-0
hw/misc/tmp421.c static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name, · line 159
Quoted 8 lines
hw/misc/tmp421.c +1
-1@@ -153,7 +153,7 @@ static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name, }if (temp >= maxs[ext_range] || temp < mins[ext_range]) { -error_setg (errp,"value %" PRId64".%03" PRIu64" °C is out of range" , +error_setg (errp,"value %" PRId64".%03" PRIu64" C is out of range" , temp /1000 , temp %1000 );return ; }
Do we have any policy in place to prohibit this in the future? (Presumably a policy that is automatic and won't interfere with QEMU localization efforts which may rightly attempt to use UTF-8 for those locales.)
Do you have a script or trick to find utf-8 containing strings in our source?
Only curious, don't hold this patch up on my account. I'm not raising a challenge.
--js
[adding Markus in CC, since git didn't do it automatically from the 'Reported-by']
Quoted 19 lines · John Snow
Quoted 8 lines · Eric Blake
While most developers are now using UTF-8 environments, it's harder to guarantee that error messages will be output to a multibyte locale. Rather than risking error messages that get corrupted into mojibake when the user runs qemu in a non-multibyte locale, let's stick to straight ASCII error messages, rather than assuming that our use of UTF-8 in source code string constants will work unchanged in other locales.
Quoted 6 lines
Reported-by Markus Armbruster <[email protected]>Signed-off-by Eric Blake <[email protected]>--- hw/misc/tmp105.c | 2 +- hw/misc/tmp421.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 4 lines
Do we have any policy in place to prohibit this in the future? (Presumably a policy that is automatic and won't interfere with QEMU localization efforts which may rightly attempt to use UTF-8 for those locales.)
Not that I know of.
Quoted 3 lines
Do you have a script or trick to find utf-8 containing strings in our source?
Markus found these two, probably by reading over a list resulting from his claim of finding 217 out of 6455 files (53 of them binary, which don't count):
https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg04017.html
My quick and dirty attempt, which does not quite reproduce his numbers:
$ LC_ALL=C git grep -l $'[\x80-\xff]' | wc
279 279 7490Thus, by forcing a unibyte locale (where encoding errors are impossible) with sane range expressions (POSIX says only the C locale is required to interpret regex ranges according to byte value - all bets are off in other locales) and using $'' to type non-UTF-8 bytes into my search, I found 279 files with at least one byte outside of ASCII. But the use of -l has no easy way to filter which of those files are binary; while dropping -l claims 2138 "lines" with non-ASCII, which gets tedious to scroll through, especially considering there ARE binary files in the mix.
Narrowing the search to a more specific pattern:
$ LC_ALL=C git grep $'".*[\x80-\xff].*"' | grep -v 'Binary file' | wc
129 685 8808is a bit more manageable, with MOST of the hits in pc-bios/qemu.rsrc (false positive hits, due to interesting? comments), in po/ (which doesn't count), or in scripts/ for python. And the proof for THIS patch:
$ LC_ALL=C git grep -l $'".*[\x80-\xff].*"' origin -- '**/*.[ch]' | cat origin:hw/misc/tmp105.c origin:hw/misc/tmp421.c
Quoted 3 lines
Only curious, don't hold this patch up on my account. I'm not raising a challenge.
Maybe checkpatch.pl could be taught to do a similar check?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
John Snow
Reviewed-byQuoted 58 lines · Eric Blake
[adding Markus in CC, since git didn't do it automatically from the 'Reported-by']
Quoted 19 lines · John Snow
Quoted 8 lines · Eric Blake
While most developers are now using UTF-8 environments, it's harder to guarantee that error messages will be output to a multibyte locale. Rather than risking error messages that get corrupted into mojibake when the user runs qemu in a non-multibyte locale, let's stick to straight ASCII error messages, rather than assuming that our use of UTF-8 in source code string constants will work unchanged in other locales.
Quoted 6 lines
Reported-by Markus Armbruster <[email protected]>Signed-off-by Eric Blake <[email protected]>---
hw/misc/tmp105.c| 2 +-
hw/misc/tmp421.c| 2 +-2 files changed, 2 insertions(+), 2 deletions(-)Quoted 4 lines
Do we have any policy in place to prohibit this in the future? (Presumably a policy that is automatic and won't interfere with QEMU localization efforts which may rightly attempt to use UTF-8 for those locales.)
Not that I know of.
Quoted 3 lines
Do you have a script or trick to find utf-8 containing strings in our source?
Markus found these two, probably by reading over a list resulting from his claim of finding 217 out of 6455 files (53 of them binary, which don't count):
https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg04017.htmlMy quick and dirty attempt, which does not quite reproduce his numbers:
$ LC_ALL=C git grep -l $'[\x80-\xff]' | wc 279 279 7490Thus, by forcing a unibyte locale (where encoding errors are impossible) with sane range expressions (POSIX says only the C locale is required to interpret regex ranges according to byte value - all bets are off in other locales) and using $'' to type non-UTF-8 bytes into my search, I found 279 files with at least one byte outside of ASCII. But the use of -l has no easy way to filter which of those files are binary; while dropping -l claims 2138 "lines" with non-ASCII, which gets tedious to scroll through, especially considering there ARE binary files in the mix.
Narrowing the search to a more specific pattern:
$ LC_ALL=C git grep $'".*[\x80-\xff].*"' | grep -v 'Binary file' | wc 129 685 8808
Quoted 8 lines
is a bit more manageable, with MOST of the hits in pc-bios/qemu.rsrc (false positive hits, due to interesting? comments), in po/ (which doesn't count), or in
scripts/for python. And the proof for THIS patch:$ LC_ALL=C git grep -l $'".*[\x80-\xff].*"' origin -- '**/*.[ch]' | cat origin:hw/misc/tmp105.c origin:hw/misc/tmp421.c
Aha!
Thanks. I was surprised we've managed to introduce only two cases of this so far. Your patch seems complete in this case.
Since I took the time to read along, I may as well:
Quoted 6 lines
Quoted 3 lines
Only curious, don't hold this patch up on my account. I'm not raising a challenge.
Maybe checkpatch.pl could be taught to do a similar check?
Philippe Mathieu-Daudé
Reviewed-byQuoted 47 lines · Eric Blake
[adding Markus in CC, since git didn't do it automatically from the 'Reported-by']
Quoted 19 lines · John Snow
Quoted 8 lines · Eric Blake
While most developers are now using UTF-8 environments, it's harder to guarantee that error messages will be output to a multibyte locale. Rather than risking error messages that get corrupted into mojibake when the user runs qemu in a non-multibyte locale, let's stick to straight ASCII error messages, rather than assuming that our use of UTF-8 in source code string constants will work unchanged in other locales.
Quoted 6 lines
Reported-by Markus Armbruster <[email protected]>Signed-off-by Eric Blake <[email protected]>---
hw/misc/tmp105.c| 2 +-
hw/misc/tmp421.c| 2 +-2 files changed, 2 insertions(+), 2 deletions(-)Quoted 4 lines
Do we have any policy in place to prohibit this in the future? (Presumably a policy that is automatic and won't interfere with QEMU localization efforts which may rightly attempt to use UTF-8 for those locales.)
Not that I know of.
Quoted 3 lines
Do you have a script or trick to find utf-8 containing strings in our source?
Markus found these two, probably by reading over a list resulting from his claim of finding 217 out of 6455 files (53 of them binary, which don't count):
https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg04017.htmlMy quick and dirty attempt, which does not quite reproduce his numbers:
$ LC_ALL=C git grep -l $'[\x80-\xff]' | wc 279 279 7490Thus, by forcing a unibyte locale (where encoding errors are impossible) with sane range expressions (POSIX says only the C locale is required to interpret regex ranges according to byte value - all bets are off in other locales) and using $'' to type non-UTF-8 bytes into my search, I found 279 files with at least one byte outside of ASCII. But the use of -l has no easy way to filter which of those files are binary; while
dropping -l claims 2138 "lines" with non-ASCII, which gets tedious to scroll through, especially considering there ARE binary files in the mix.Narrowing the search to a more specific pattern:
Quoted 8 lines
$ LC_ALL=C git grep $'".*[\x80-\xff].*"' | grep -v 'Binary file' | wc 129 685 8808is a bit more manageable, with MOST of the hits in pc-bios/qemu.rsrc (false positive hits, due to interesting? comments), in po/ (which doesn't count), or in
scripts/for python. And the proof for THIS patch:$ LC_ALL=C git grep -l $'".*[\x80-\xff].*"' origin -- '**/*.[ch]' | cat origin:hw/misc/tmp105.c origin:hw/misc/tmp421.c
Can we add the last 3 lines in the commit message?
Quoted 6 lines
Quoted 4 lines
Only curious, don't hold this patch up on my account. I'm not raising a challenge.
Maybe checkpatch.pl could be taught to do a similar check?
It looks easier in shell than perl...
We could add a checkpatch.sh which finally call 'exec -l checkpatch.pl $@' or similar?
Markus Armbruster
Reviewed-byQuoted 24 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Eric Blake
[adding Markus in CC, since git didn't do it automatically from the 'Reported-by']
Quoted 19 lines · John Snow
Quoted 14 lines · Eric Blake
While most developers are now using UTF-8 environments, it's harder to guarantee that error messages will be output to a multibyte locale. Rather than risking error messages that get corrupted into mojibake when the user runs qemu in a non-multibyte locale, let's stick to straight ASCII error messages, rather than assuming that our use of UTF-8 in source code string constants will work unchanged in other locales.
Reported-by Markus Armbruster <[email protected]>Signed-off-by Eric Blake <[email protected]>---
hw/misc/tmp105.c| 2 +-
hw/misc/tmp421.c| 2 +-2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Do we have any policy in place to prohibit this in the future? (Presumably a policy that is automatic and won't interfere with QEMU localization efforts which may rightly attempt to use UTF-8 for those locales.)
Not that I know of.
We already outlaw newline and trailing punctuation, we could amend that to outlaw non-ASCII.
$ git-grep 'no newline' include/qapi/error.h: * The resulting message should be a single phrase, with no newline or util/qemu-error.c: * a single phrase, with no newline or trailing punctuation. util/qemu-error.c: * a single phrase, with no newline or trailing punctuation. util/qemu-error.c: * a single phrase, with no newline or trailing punctuation. util/qemu-error.c: * a single phrase, with no newline or trailing punctuation. util/qemu-error.c: * a single phrase, with no newline or trailing punctuation. util/qemu-error.c: * single phrase, with no newline or trailing punctuation. util/qemu-error.c: * single phrase, with no newline or trailing punctuation.
[...]
Quoted 6 lines
Quoted 1 line
Maybe checkpatch.pl could be taught to do a similar check?
It looks easier in shell than perl...
We could add a
checkpatch.shwhich finally call 'exec -l checkpatch.pl $@' or similar?
Congratulations, you found yet another way to make our checkpatch program less readable.
Back to serious. checkpatch.pl already flags error messages containing newlines (search for "should not contain newlines"). Extending that to flag non-ASCII characters shouldn't be hard.
Quoted 1 line
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 34 lines · Eric Blake
While most developers are now using UTF-8 environments, it's harder to guarantee that error messages will be output to a multibyte locale. Rather than risking error messages that get corrupted into mojibake when the user runs qemu in a non-multibyte locale, let's stick to straight ASCII error messages, rather than assuming that our use of UTF-8 in source code string constants will work unchanged in other locales.
Reported-by Markus Armbruster <[email protected]>Signed-off-by Eric Blake <[email protected]>--- hw/misc/tmp105.c | 2 +- hw/misc/tmp421.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/misc/tmp105.c +1
-1@@ -79,7 +79,7 @@ static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,return ; }if (temp >=128000 || temp <-128000 ) { -error_setg (errp,"value %" PRId64".%03" PRIu64" °C is out of range" , +error_setg (errp,"value %" PRId64".%03" PRIu64" C is out of range" , temp /1000 , temp %1000 );return ; }hw/misc/tmp421.c +0
-0
hw/misc/tmp421.c static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name, · line 159
Quoted 8 lines
hw/misc/tmp421.c +1
-1@@ -153,7 +153,7 @@ static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name, }if (temp >= maxs[ext_range] || temp < mins[ext_range]) { -error_setg (errp,"value %" PRId64".%03" PRIu64" °C is out of range" , +error_setg (errp,"value %" PRId64".%03" PRIu64" C is out of range" , temp /1000 , temp %1000 );return ; }
Laurent Vivier
AppliedQuoted 34 lines · Eric Blake
While most developers are now using UTF-8 environments, it's harder to guarantee that error messages will be output to a multibyte locale. Rather than risking error messages that get corrupted into mojibake when the user runs qemu in a non-multibyte locale, let's stick to straight ASCII error messages, rather than assuming that our use of UTF-8 in source code string constants will work unchanged in other locales.
Reported-by Markus Armbruster <[email protected]>Signed-off-by Eric Blake <[email protected]>--- hw/misc/tmp105.c | 2 +- hw/misc/tmp421.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/misc/tmp105.c +1
-1@@ -79,7 +79,7 @@ static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,return ; }if (temp >=128000 || temp <-128000 ) { -error_setg (errp,"value %" PRId64".%03" PRIu64" °C is out of range" , +error_setg (errp,"value %" PRId64".%03" PRIu64" C is out of range" , temp /1000 , temp %1000 );return ; }hw/misc/tmp421.c +0
-0
hw/misc/tmp421.c static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name, · line 159
Quoted 8 lines
hw/misc/tmp421.c +1
-1@@ -153,7 +153,7 @@ static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name, }if (temp >= maxs[ext_range] || temp < mins[ext_range]) { -error_setg (errp,"value %" PRId64".%03" PRIu64" °C is out of range" , +error_setg (errp,"value %" PRId64".%03" PRIu64" C is out of range" , temp /1000 , temp %1000 );return ; }
Applied to qemu-trivial with updated message log (command to find the non-ASCII characters).
Thanks,
Laurent