Skip to contentSkip to conversation

msvc: fix non-standard escape sequence in source

PATCH In review [email protected] 4 participants 5 messages Jul 24, 2018 – Jul 25, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 msvc: fix non-standard escape sequence in source

From: Jeff Hostetler <[email protected]>

Replace non-standard "\e" escape sequence with "\x1B".

In commit 7a17918c34f4e83982456ffe22d880c3cda5384f a trace message with several "\e" escape sequences was added. This causes a compiler warning under MSVC.

According to [1], the "\e" sequence is an extension supported by GCC, clang, and tcc.

[1] https://en.wikipedia.org/wiki/Escape_sequences_in_C

---
 convert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
convert.c +1 -1
index 56cfe31..52092be 100644
@@ -335,7 +335,7 @@ static void trace_encoding(const char *context, const char *path,
 	strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
 	for (i = 0; i < len && buf; ++i) {
 		strbuf_addf(
-			&trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
+			&trace,"| \x1B[2m%2i:\x1B[0m %2x \x1B[2m%c\x1B[0m%c",
 			i,
 			(unsigned char) buf[i],
 			(buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '),
Signature · 1 line
2.9.3
#1 lore raw
Quoted 5 lines · On Tue, Jul 24, 2018 at 10:43 AM <[email protected]> wrote:

Replace non-standard "\e" escape sequence with "\x1B".

In commit 7a17918c34f4e83982456ffe22d880c3cda5384f a trace message with several "\e" escape sequences was added. This causes a compiler warning under MSVC.

Wrong commit. That code was actually introduced by 541d059cd9 (convert: add tracing for 'working-tree-encoding' attribute, 2018-04-15).

convert.c static void trace_encoding(const char *context, const char *path, · line 338

Quoted 7 lines
convert.c +1 -1
@@ -335,7 +335,7 @@ static void trace_encoding(const char *context, const char *path,
        strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
        for (i = 0; i < len && buf; ++i) {
                strbuf_addf(
-                       &trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
+                       &trace,"| \x1B[2m%2i:\x1B[0m %2x \x1B[2m%c\x1B[0m%c",

In this codebase, ESC is always spelled as octal \033 rather than hex \x1b.

#2 lore raw
In reply to [email protected]
Quoted 10 lines · [email protected] writes:

From: Jeff Hostetler <[email protected]>

Replace non-standard "\e" escape sequence with "\x1B".

In commit 7a17918c34f4e83982456ffe22d880c3cda5384f a trace message with several "\e" escape sequences was added. This causes a compiler warning under MSVC.

According to [1], the "\e" sequence is an extension supported by GCC, clang, and tcc.

Good spotting. Please spell it \x1b (or \033 if you are a traditionalist), as it seems nobody in the existing code uses uppercase, according to

    $ git grep -e '\\x[A-F][0-9A-F]' -e '\\x[0-9A-F][A-F]' \*.c

and "\033" is already used in many places

    $ git grep -e '\\0[0-7][0-7]' \*.c
Quoted 20 lines

[1] https://en.wikipedia.org/wiki/Escape_sequences_in_C

---
 convert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
convert.c +1 -1
index 56cfe31..52092be 100644
@@ -335,7 +335,7 @@ static void trace_encoding(const char *context, const char *path,
 	strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
 	for (i = 0; i < len && buf; ++i) {
 		strbuf_addf(
-			&trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
+			&trace,"| \x1B[2m%2i:\x1B[0m %2x \x1B[2m%c\x1B[0m%c",
 			i,
 			(unsigned char) buf[i],
 			(buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '),
#3 lore raw
In reply to [email protected]

Hi Jeff

Quoted 3 lines · On 24.07.18 16:42, [email protected] wrote:

From: Jeff Hostetler <[email protected]>

Replace non-standard "\e" escape sequence with "\x1B".

This was already fixed in <[email protected]>.

Cheers,
Beat

Quoted 29 lines

In commit 7a17918c34f4e83982456ffe22d880c3cda5384f a trace message with several "\e" escape sequences was added. This causes a compiler warning under MSVC.

According to [1], the "\e" sequence is an extension supported by GCC, clang, and tcc.

[1] https://en.wikipedia.org/wiki/Escape_sequences_in_C

---
 convert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
convert.c +1 -1
index 56cfe31..52092be 100644
@@ -335,7 +335,7 @@ static void trace_encoding(const char *context, const char *path,
 	strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
 	for (i = 0; i < len && buf; ++i) {
 		strbuf_addf(
-			&trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
+			&trace,"| \x1B[2m%2i:\x1B[0m %2x \x1B[2m%c\x1B[0m%c",
 			i,
 			(unsigned char) buf[i],
 			(buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '),
#4 lore raw
Quoted 12 lines · Beat Bolli

Hi Jeff

Quoted 3 lines · On 24.07.18 16:42, [email protected] wrote:

From: Jeff Hostetler <[email protected]>

Replace non-standard "\e" escape sequence with "\x1B".

This was already fixed in <[email protected]>.

Cheers,
Beat

Thanks for the pointer. I see that commit is in 'next'. I was only looking in 'master'.

Thanks,
Jeff