]> granicus.if.org Git - strace/commitdiff
util.c: reduce indentation in non-hexadecimal case in string_quote
authorEugene Syromyatnikov <evgsyr@gmail.com>
Thu, 1 Feb 2018 19:13:53 +0000 (20:13 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 1 Mar 2018 01:00:24 +0000 (01:00 +0000)
As it is already too deep there.

* util.c (string_quote): Add string_ended label, jump there
after the loop in "if (usehex)" case.

util.c

diff --git a/util.c b/util.c
index ddba53ca71f254cedd55e7441058d0923663010b..6df1239aa188ef035eb339b4bdca395a7d96167b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -514,67 +514,70 @@ string_quote(const char *instr, char *outstr, const unsigned int size,
                        *s++ = "0123456789abcdef"[c >> 4];
                        *s++ = "0123456789abcdef"[c & 0xf];
                }
-       } else {
-               for (i = 0; i < size; ++i) {
-                       c = ustr[i];
-                       /* Check for NUL-terminated string. */
-                       if (c == eol)
-                               goto asciz_ended;
-                       if ((i == (size - 1)) &&
-                           (style & QUOTE_OMIT_TRAILING_0) && (c == '\0'))
-                               goto asciz_ended;
-                       switch (c) {
-                       case '\"': case '\\':
-                               *s++ = '\\';
+
+               goto string_ended;
+       }
+
+       for (i = 0; i < size; ++i) {
+               c = ustr[i];
+               /* Check for NUL-terminated string. */
+               if (c == eol)
+                       goto asciz_ended;
+               if ((i == (size - 1)) &&
+                   (style & QUOTE_OMIT_TRAILING_0) && (c == '\0'))
+                       goto asciz_ended;
+               switch (c) {
+               case '\"': case '\\':
+                       *s++ = '\\';
+                       *s++ = c;
+                       break;
+               case '\f':
+                       *s++ = '\\';
+                       *s++ = 'f';
+                       break;
+               case '\n':
+                       *s++ = '\\';
+                       *s++ = 'n';
+                       break;
+               case '\r':
+                       *s++ = '\\';
+                       *s++ = 'r';
+                       break;
+               case '\t':
+                       *s++ = '\\';
+                       *s++ = 't';
+                       break;
+               case '\v':
+                       *s++ = '\\';
+                       *s++ = 'v';
+                       break;
+               default:
+                       if (c >= ' ' && c <= 0x7e)
                                *s++ = c;
-                               break;
-                       case '\f':
-                               *s++ = '\\';
-                               *s++ = 'f';
-                               break;
-                       case '\n':
-                               *s++ = '\\';
-                               *s++ = 'n';
-                               break;
-                       case '\r':
-                               *s++ = '\\';
-                               *s++ = 'r';
-                               break;
-                       case '\t':
-                               *s++ = '\\';
-                               *s++ = 't';
-                               break;
-                       case '\v':
+                       else {
+                               /* Print \octal */
                                *s++ = '\\';
-                               *s++ = 'v';
-                               break;
-                       default:
-                               if (c >= ' ' && c <= 0x7e)
-                                       *s++ = c;
-                               else {
-                                       /* Print \octal */
-                                       *s++ = '\\';
-                                       if (i + 1 < size
-                                           && ustr[i + 1] >= '0'
-                                           && ustr[i + 1] <= '9'
-                                       ) {
-                                               /* Print \ooo */
-                                               *s++ = '0' + (c >> 6);
+                               if (i + 1 < size
+                                   && ustr[i + 1] >= '0'
+                                   && ustr[i + 1] <= '9'
+                               ) {
+                                       /* Print \ooo */
+                                       *s++ = '0' + (c >> 6);
+                                       *s++ = '0' + ((c >> 3) & 0x7);
+                               } else {
+                                       /* Print \[[o]o]o */
+                                       if ((c >> 3) != 0) {
+                                               if ((c >> 6) != 0)
+                                                       *s++ = '0' + (c >> 6);
                                                *s++ = '0' + ((c >> 3) & 0x7);
-                                       } else {
-                                               /* Print \[[o]o]o */
-                                               if ((c >> 3) != 0) {
-                                                       if ((c >> 6) != 0)
-                                                               *s++ = '0' + (c >> 6);
-                                                       *s++ = '0' + ((c >> 3) & 0x7);
-                                               }
                                        }
-                                       *s++ = '0' + (c & 0x7);
                                }
+                               *s++ = '0' + (c & 0x7);
                        }
                }
        }
 
+ string_ended:
        if (!(style & QUOTE_OMIT_LEADING_TRAILING_QUOTES))
                *s++ = '\"';
        if (style & QUOTE_EMIT_COMMENT)