{"thread":{"id":"59858","subject":"[PATCH v2] CodingGuidelines: use octal escapes, not hex","startedAt":"2023-06-14T00:16:05Z","lastAt":"2023-06-14T21:54:57Z","messageCount":4,"participants":["Jonathan Tan","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"478348","messageId":"20230614001558.277755-1-jonathantanmy@google.com","threadId":"59858","inReplyTo":null,"subject":"[PATCH v2] CodingGuidelines: use octal escapes, not hex","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2023-06-14T00:15:58Z","receivedAt":"2023-06-14T00:16:05Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"Extend the shell-scripting section of CodingGuidelines to suggest octal\nescape sequences (e.g. \"\\302\\242\") over hexadecimal (e.g. \"\\xc2\\xa2\")\nsince the latter can be a source of portability problems.\n\nSigned-off-by: Jonathan Tan <jonathantanmy@google.com>\n---\nI've used Eric's suggestion for the commit message and limited the scope\nof the documentation change to printf.\n\nVersion 1 was here:\nhttps://lore.kernel.org/git/20230613172927.19019-1-jonathantanmy@google.com/\n---\n Documentation/CodingGuidelines | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines\nindex 003393ed16..30ac7d2d3f 100644\n--- a/Documentation/CodingGuidelines\n+++ b/Documentation/CodingGuidelines\n@@ -188,6 +188,10 @@ For shell scripts specifically (not exhaustive):\n    hopefully nobody starts using \"local\" before they are reimplemented\n    in C ;-)\n \n+ - Use octal escape sequences (e.g. \"\\302\\242\"), not hexadecimal (e.g.\n+   \"\\xc2\\xa2\"), since the latter is not portable across commands like\n+   \"printf\".\n+\n \n For C programs:\n \n-- \n2.41.0.162.gfafddb0af9-goog\n\n"},{"id":"478350","messageId":"xmqqy1km28g9.fsf@gitster.g","threadId":"59858","inReplyTo":"20230614001558.277755-1-jonathantanmy@google.com","subject":"Re: [PATCH v2] CodingGuidelines: use octal escapes, not hex","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-06-14T00:28:38Z","receivedAt":"2023-06-14T00:28:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Tan <jonathantanmy@google.com> writes:\n\n> Extend the shell-scripting section of CodingGuidelines to suggest octal\n> escape sequences (e.g. \"\\302\\242\") over hexadecimal (e.g. \"\\xc2\\xa2\")\n> since the latter can be a source of portability problems.\n>\n> Signed-off-by: Jonathan Tan <jonathantanmy@google.com>\n> ---\n> I've used Eric's suggestion for the commit message and limited the scope\n> of the documentation change to printf.\n>\n> Version 1 was here:\n> https://lore.kernel.org/git/20230613172927.19019-1-jonathantanmy@google.com/\n> ---\n>  Documentation/CodingGuidelines | 4 ++++\n>  1 file changed, 4 insertions(+)\n>\n> diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines\n> index 003393ed16..30ac7d2d3f 100644\n> --- a/Documentation/CodingGuidelines\n> +++ b/Documentation/CodingGuidelines\n> @@ -188,6 +188,10 @@ For shell scripts specifically (not exhaustive):\n>     hopefully nobody starts using \"local\" before they are reimplemented\n>     in C ;-)\n>  \n> + - Use octal escape sequences (e.g. \"\\302\\242\"), not hexadecimal (e.g.\n> +   \"\\xc2\\xa2\"), since the latter is not portable across commands like\n> +   \"printf\".\n\nI'd say\n\n    - Use octal ... not hex..., in printf format string.\n\nnot \"commands LIKE\".\n\nThanks.\n\n"},{"id":"478397","messageId":"20230614213145.475607-1-jonathantanmy@google.com","threadId":"59858","inReplyTo":"20230614001558.277755-1-jonathantanmy@google.com","subject":"[PATCH v3] CodingGuidelines: use octal escapes, not hex","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2023-06-14T21:31:45Z","receivedAt":"2023-06-14T21:31:54Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"Extend the shell-scripting section of CodingGuidelines to suggest octal\nescape sequences (e.g. \"\\302\\242\") over hexadecimal (e.g. \"\\xc2\\xa2\")\nsince the latter can be a source of portability problems.\n\nSigned-off-by: Jonathan Tan <jonathantanmy@google.com>\n---\nChanges in v3: Used Junio's suggestion [1].\n\n[1] https://lore.kernel.org/git/xmqqy1km28g9.fsf@gitster.g/\n---\nRange-diff against v2:\n1:  c775a0db22 ! 1:  0b7d3ed8f5 CodingGuidelines: use octal escapes, not hex\n    @@ Commit message\n     \n         Signed-off-by: Jonathan Tan <jonathantanmy@google.com>\n         ---\n    -    I've used Eric's suggestion for the commit message and limited the scope\n    -    of the documentation change to printf.\n    +    Changes in v3: Used Junio's suggestion [1].\n     \n    -    Version 1 was here:\n    -    https://lore.kernel.org/git/20230613172927.19019-1-jonathantanmy@google.com/\n    +    [1] https://lore.kernel.org/git/xmqqy1km28g9.fsf@gitster.g/\n     \n      ## Documentation/CodingGuidelines ##\n     @@ Documentation/CodingGuidelines: For shell scripts specifically (not exhaustive):\n    @@ Documentation/CodingGuidelines: For shell scripts specifically (not exhaustive):\n         in C ;-)\n      \n     + - Use octal escape sequences (e.g. \"\\302\\242\"), not hexadecimal (e.g.\n    -+   \"\\xc2\\xa2\"), since the latter is not portable across commands like\n    -+   \"printf\".\n    ++   \"\\xc2\\xa2\") in printf format strings, since hexadecimal escape\n    ++   sequences are not portable.\n     +\n      \n      For C programs:\n\n Documentation/CodingGuidelines | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines\nindex 003393ed16..39ef53c237 100644\n--- a/Documentation/CodingGuidelines\n+++ b/Documentation/CodingGuidelines\n@@ -188,6 +188,10 @@ For shell scripts specifically (not exhaustive):\n    hopefully nobody starts using \"local\" before they are reimplemented\n    in C ;-)\n \n+ - Use octal escape sequences (e.g. \"\\302\\242\"), not hexadecimal (e.g.\n+   \"\\xc2\\xa2\") in printf format strings, since hexadecimal escape\n+   sequences are not portable.\n+\n \n For C programs:\n \n-- \n2.41.0.162.gfafddb0af9-goog\n\n"},{"id":"478403","messageId":"xmqqo7lhwvyt.fsf@gitster.g","threadId":"59858","inReplyTo":"20230614213145.475607-1-jonathantanmy@google.com","subject":"Re: [PATCH v3] CodingGuidelines: use octal escapes, not hex","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-06-14T21:54:50Z","receivedAt":"2023-06-14T21:54:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Tan <jonathantanmy@google.com> writes:\n\n> Extend the shell-scripting section of CodingGuidelines to suggest octal\n> escape sequences (e.g. \"\\302\\242\") over hexadecimal (e.g. \"\\xc2\\xa2\")\n> since the latter can be a source of portability problems.\n\nSounds good.  On a typical GNU system, /usr/bin/printf as well as\nprintf built into bash groks \"\\x<hex>\" escapes in its format string,\nbut we cannot depend on it because POSIX does not require support\nfor \"\\x<hex>\", and printf built into dash indeed does not.  It is a\ngood idea to stress that this is specifically about the format\nstring (in other words, nothing magical happens when using octal or\nhex escapes in say \"printf '%s\\n' '\\302\\242'\").\n\n> + - Use octal escape sequences (e.g. \"\\302\\242\"), not hexadecimal (e.g.\n> +   \"\\xc2\\xa2\") in printf format strings, since hexadecimal escape\n> +   sequences are not portable.\n\nWill queue.  Thanks.\n"}]}