From 642c2dee44acbb35045515f3a012e24b24c79776 Mon Sep 17 00:00:00 2001 From: ColMelvin Date: Thu, 13 Oct 2022 13:05:05 -0500 Subject: [PATCH] cstyle: Allow URLs in C++ comments If a C++ comment contained a URL, the `://` part of the URL would trigger an error because there was no trailing blank, but trailing blanks make for an invalid URL. Modify the check to ignore text within the C++ comment. Reviewed-by: Brian Behlendorf Signed-off-by: Chris Lindee Closes #13987 --- scripts/cstyle.pl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/cstyle.pl b/scripts/cstyle.pl index ca7f027051cc..d47fd3362408 100755 --- a/scripts/cstyle.pl +++ b/scripts/cstyle.pl @@ -498,9 +498,6 @@ line: while (<$filehandle>) { if (/\S\*\/[^)]|\S\*\/$/ && !/$lint_re/) { err("missing blank before close comment"); } - if (/\/\/\S/) { # C++ comments - err("missing blank after start comment"); - } # check for unterminated single line comments, but allow them when # they are used to comment out the argument list of a function # declaration. @@ -534,7 +531,15 @@ line: while (<$filehandle>) { # multiple comments on the same line. # s/\/\*.*?\*\///g; - s/\/\/.*$//; # C++ comments + s/\/\/(?:\s.*)?$//; # Valid C++ comments + + # After stripping correctly spaced comments, check for (and strip) comments + # without a blank. By checking this after clearing out C++ comments that + # correctly have a blank, we guarantee URIs in a C++ comment will not cause + # an error. + if (s!//.*$!!) { # C++ comments + err("missing blank after start comment"); + } # delete any trailing whitespace; we have already checked for that. s/\s*$//;