* scripts/checkpatch: Concatenated strings should use spaces between elements @ 2017-10-17 21:17 Heinrich Schuchardt 2017-10-17 22:43 ` Joe Perches 0 siblings, 1 reply; 6+ messages in thread From: Heinrich Schuchardt @ 2017-10-17 21:17 UTC (permalink / raw) To: Andy Whitcroft, Joe Perches; +Cc: linux-kernel, Heinrich Schuchardt This patch creates a warning (CHECK) "Concatenated strings should use spaces between elements" There are no concatenated strings here. (checkpatch is also used in the U-Boot project where wide strings occur in the EFI implementation.) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> --- test.c | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test.c diff --git a/test.c b/test.c new file mode 100644 index 0000000000..dfd33cd765 --- /dev/null +++ b/test.c @@ -0,0 +1,6 @@ +#include <foo.h> + +void foo(void) +{ + test(L"\""); +} -- 2.14.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: scripts/checkpatch: Concatenated strings should use spaces between elements 2017-10-17 21:17 scripts/checkpatch: Concatenated strings should use spaces between elements Heinrich Schuchardt @ 2017-10-17 22:43 ` Joe Perches 2017-10-17 22:58 ` Heinrich Schuchardt 0 siblings, 1 reply; 6+ messages in thread From: Joe Perches @ 2017-10-17 22:43 UTC (permalink / raw) To: Heinrich Schuchardt, Andy Whitcroft; +Cc: linux-kernel On Tue, 2017-10-17 at 23:17 +0200, Heinrich Schuchardt wrote: > This patch creates a warning (CHECK) > "Concatenated strings should use spaces between elements" > > There are no concatenated strings here. Yes, there are. > (checkpatch is also used in the U-Boot project where wide strings > occur in the EFI implementation.) > > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> > --- > test.c | 7 +++++++ > 1 file changed, 7 insertions(+) > create mode 100644 test.c > > diff --git a/test.c b/test.c > new file mode 100644 > index 0000000000..dfd33cd765 > --- /dev/null > +++ b/test.c > @@ -0,0 +1,6 @@ > +#include <foo.h> > + > +void foo(void) > +{ > + test(L"\""); In this case, L must be a constant string and you are concatenating L and "\"" ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scripts/checkpatch: Concatenated strings should use spaces between elements 2017-10-17 22:43 ` Joe Perches @ 2017-10-17 22:58 ` Heinrich Schuchardt 2017-10-17 23:18 ` Joe Perches 2017-10-18 0:35 ` Joe Perches 0 siblings, 2 replies; 6+ messages in thread From: Heinrich Schuchardt @ 2017-10-17 22:58 UTC (permalink / raw) To: Joe Perches, Andy Whitcroft; +Cc: linux-kernel On 10/18/2017 12:43 AM, Joe Perches wrote: > On Tue, 2017-10-17 at 23:17 +0200, Heinrich Schuchardt wrote: >> This patch creates a warning (CHECK) >> "Concatenated strings should use spaces between elements" >> >> There are no concatenated strings here. > > Yes, there are. > >> (checkpatch is also used in the U-Boot project where wide strings >> occur in the EFI implementation.) >> >> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> >> --- >> test.c | 7 +++++++ >> 1 file changed, 7 insertions(+) >> create mode 100644 test.c >> >> diff --git a/test.c b/test.c >> new file mode 100644 >> index 0000000000..dfd33cd765 >> --- /dev/null >> +++ b/test.c >> @@ -0,0 +1,6 @@ >> +#include <foo.h> >> + >> +void foo(void) >> +{ >> + test(L"\""); > > In this case, L must be a constant string and you > are concatenating L and "\"" > > See ISO/IEC 9899:1999 6.4.5 String literals <cite> A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in "xyz" A wide string literal is the same, except prefixed by the letter L. </cite> L"foo" is a literal of type wchar_t * and not two strings. L is a qualifier and not a constant string. Just like ULL in 10ULL. Regards Heinrich ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scripts/checkpatch: Concatenated strings should use spaces between elements 2017-10-17 22:58 ` Heinrich Schuchardt @ 2017-10-17 23:18 ` Joe Perches 2017-10-18 0:35 ` Joe Perches 1 sibling, 0 replies; 6+ messages in thread From: Joe Perches @ 2017-10-17 23:18 UTC (permalink / raw) To: Heinrich Schuchardt, Andy Whitcroft; +Cc: linux-kernel On Wed, 2017-10-18 at 00:58 +0200, Heinrich Schuchardt wrote: > On 10/18/2017 12:43 AM, Joe Perches wrote: > > On Tue, 2017-10-17 at 23:17 +0200, Heinrich Schuchardt wrote: > > > This patch creates a warning (CHECK) > > > "Concatenated strings should use spaces between elements" > > > > > > There are no concatenated strings here. > > > > Yes, there are. > > > > > (checkpatch is also used in the U-Boot project where wide strings > > > occur in the EFI implementation.) > > > > > > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> > > > --- > > > test.c | 7 +++++++ > > > 1 file changed, 7 insertions(+) > > > create mode 100644 test.c > > > > > > diff --git a/test.c b/test.c > > > new file mode 100644 > > > index 0000000000..dfd33cd765 > > > --- /dev/null > > > +++ b/test.c > > > @@ -0,0 +1,6 @@ > > > +#include <foo.h> > > > + > > > +void foo(void) > > > +{ > > > + test(L"\""); > > > > In this case, L must be a constant string and you > > are concatenating L and "\"" > > > > > > See ISO/IEC 9899:1999 > > 6.4.5 String literals > > <cite> > A character string literal is a sequence of zero or more multibyte > characters enclosed in double-quotes, as in "xyz" > A wide string literal is the same, except prefixed by the > letter L. > </cite> Kernel doesn't support wide strings. > L"foo" is a literal of type wchar_t * and not two strings. > L is a qualifier and not a constant string. > > Just like ULL in 10ULL. > > Regards > > Heinrich ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scripts/checkpatch: Concatenated strings should use spaces between elements 2017-10-17 22:58 ` Heinrich Schuchardt 2017-10-17 23:18 ` Joe Perches @ 2017-10-18 0:35 ` Joe Perches 2017-10-18 6:32 ` Heinrich Schuchardt 1 sibling, 1 reply; 6+ messages in thread From: Joe Perches @ 2017-10-18 0:35 UTC (permalink / raw) To: Heinrich Schuchardt, Andy Whitcroft; +Cc: linux-kernel On Wed, 2017-10-18 at 00:58 +0200, Heinrich Schuchardt wrote: > On 10/18/2017 12:43 AM, Joe Perches wrote: > > On Tue, 2017-10-17 at 23:17 +0200, Heinrich Schuchardt wrote: > > > This patch creates a warning (CHECK) > > > "Concatenated strings should use spaces between elements" [] > > > +void foo(void) > > > +{ > > > + test(L"\""); > > > > In this case, L must be a constant string and you > > are concatenating L and "\"" > > > > > > See ISO/IEC 9899:1999 > > 6.4.5 String literals > > <cite> > A character string literal is a sequence of zero or more multibyte > characters enclosed in double-quotes, as in "xyz" > A wide string literal is the same, except prefixed by the > letter L. > </cite> > > L"foo" is a literal of type wchar_t * and not two strings. > L is a qualifier and not a constant string. > > Just like ULL in 10ULL. How about trying this: >From 99bd0ab78a810f537e18a24be42379a6af9d5045 Mon Sep 17 00:00:00 2001 Message-Id: <99bd0ab78a810f537e18a24be42379a6af9d5045.1508286849.git.joe@perches.com> From: Joe Perches <joe@perches.com> Date: Tue, 17 Oct 2017 17:11:14 -0700 Subject: [PATCH] checkpatch: Support wide strings Allow prefixing typical strings with L for wide strings Signed-off-by: Joe Perches <joe@perches.com> --- scripts/checkpatch.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 359c02b0954e..9f04f803e96b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -393,7 +393,7 @@ our $Binary = qr{(?i)0b[01]+$Int_type?}; our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; our $Int = qr{[0-9]+$Int_type?}; our $Octal = qr{0[0-7]+$Int_type?}; -our $String = qr{"[X\t]*"}; +our $String = qr{(?:\bL)?"[X\t]*"}; our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; @@ -5262,13 +5262,14 @@ sub process { } # concatenated string without spaces between elements - if ($line =~ /$String[A-Z_]/ || $line =~ /[A-Za-z0-9_]$String/) { + if ($line =~ /$String[A-Z_]/ || + ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^L$/)) { CHK("CONCATENATED_STRING", "Concatenated strings should use spaces between elements\n" . $herecurr); } # uncoalesced string fragments - if ($line =~ /$String\s*"/) { + if ($line =~ /$String\s*L?"/) { WARN("STRING_FRAGMENTS", "Consecutive strings are generally better as a single string\n" . $herecurr); } -- 2.10.0.rc2.1.g053435c ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: scripts/checkpatch: Concatenated strings should use spaces between elements 2017-10-18 0:35 ` Joe Perches @ 2017-10-18 6:32 ` Heinrich Schuchardt 0 siblings, 0 replies; 6+ messages in thread From: Heinrich Schuchardt @ 2017-10-18 6:32 UTC (permalink / raw) To: Joe Perches, Andy Whitcroft; +Cc: linux-kernel On 10/18/2017 02:35 AM, Joe Perches wrote: > On Wed, 2017-10-18 at 00:58 +0200, Heinrich Schuchardt wrote: >> On 10/18/2017 12:43 AM, Joe Perches wrote: >>> On Tue, 2017-10-17 at 23:17 +0200, Heinrich Schuchardt wrote: >>>> This patch creates a warning (CHECK) >>>> "Concatenated strings should use spaces between elements" > [] >>>> +void foo(void) >>>> +{ >>>> + test(L"\""); >>> >>> In this case, L must be a constant string and you >>> are concatenating L and "\"" >>> >>> >> >> See ISO/IEC 9899:1999 >> >> 6.4.5 String literals >> >> <cite> >> A character string literal is a sequence of zero or more multibyte >> characters enclosed in double-quotes, as in "xyz" >> A wide string literal is the same, except prefixed by the >> letter L. >> </cite> >> >> L"foo" is a literal of type wchar_t * and not two strings. >> L is a qualifier and not a constant string. >> >> Just like ULL in 10ULL. > > How about trying this: > >>From 99bd0ab78a810f537e18a24be42379a6af9d5045 Mon Sep 17 00:00:00 2001 > Message-Id: <99bd0ab78a810f537e18a24be42379a6af9d5045.1508286849.git.joe@perches.com> > From: Joe Perches <joe@perches.com> > Date: Tue, 17 Oct 2017 17:11:14 -0700 > Subject: [PATCH] checkpatch: Support wide strings > > Allow prefixing typical strings with L for wide strings > > Signed-off-by: Joe Perches <joe@perches.com> > --- > scripts/checkpatch.pl | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 359c02b0954e..9f04f803e96b 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -393,7 +393,7 @@ our $Binary = qr{(?i)0b[01]+$Int_type?}; > our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; > our $Int = qr{[0-9]+$Int_type?}; > our $Octal = qr{0[0-7]+$Int_type?}; > -our $String = qr{"[X\t]*"}; > +our $String = qr{(?:\bL)?"[X\t]*"}; > our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; > our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; > our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; > @@ -5262,13 +5262,14 @@ sub process { > } > > # concatenated string without spaces between elements > - if ($line =~ /$String[A-Z_]/ || $line =~ /[A-Za-z0-9_]$String/) { > + if ($line =~ /$String[A-Z_]/ || > + ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^L$/)) { > CHK("CONCATENATED_STRING", > "Concatenated strings should use spaces between elements\n" . $herecurr); > } > > # uncoalesced string fragments > - if ($line =~ /$String\s*"/) { > + if ($line =~ /$String\s*L?"/) { > WARN("STRING_FRAGMENTS", > "Consecutive strings are generally better as a single string\n" . $herecurr); > } > -- > 2.10.0.rc2.1.g053435c > > The patch solves my problem. Thank you. Best regards Heinrich ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-10-18 6:32 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-10-17 21:17 scripts/checkpatch: Concatenated strings should use spaces between elements Heinrich Schuchardt 2017-10-17 22:43 ` Joe Perches 2017-10-17 22:58 ` Heinrich Schuchardt 2017-10-17 23:18 ` Joe Perches 2017-10-18 0:35 ` Joe Perches 2017-10-18 6:32 ` Heinrich Schuchardt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox