log_format_log_line: Move variable declarations near to their usage 53/237153/4
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 25 Jun 2020 09:54:35 +0000 (11:54 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 25 Jun 2020 15:26:56 +0000 (17:26 +0200)
Change-Id: Ie7dc69005c1a05c2d3c0c4ae58ed65e898b8f33a

src/shared/logprint.c

index f4b544a..ccce864 100644 (file)
@@ -838,7 +838,6 @@ char *log_format_log_line(
        char prefixBuf[128], suffixBuf[128];
        int prefixSuffixIsHeaderFooter = 0;
        const char *tag, *msg;
-       char * ret = NULL;
        int message_len = entry->len - sizeof(dlogutil_entry_s) - entry->tag_len - 2 /* tag and msg delimiters */;
        char priChar = filter_pri_to_char((log_priority)entry->priority);
 
@@ -1003,11 +1002,6 @@ char *log_format_log_line(
 
        /* the following code is tragically unreadable */
 
-       size_t numLines;
-       char *p;
-       size_t bufferSize;
-       const char *pm;
-
        const char *const pre_color_prefix = get_pre_color((log_priority)entry->priority, colorPrefix && p_format.color);
        const char *const pre_color_suffix = get_pre_color((log_priority)entry->priority, colorSuffix && p_format.color);
        const char *const post_color_prefix = get_post_color((log_priority)entry->priority, colorPrefix && p_format.color);
@@ -1017,6 +1011,9 @@ char *log_format_log_line(
        const int pre_color_suffix_len = strlen(pre_color_suffix);
        const int post_color_suffix_len = strlen(post_color_suffix);
 
+       size_t numLines;
+       const char *pm;
+
        if (prefixSuffixIsHeaderFooter) {
                /* we're just wrapping message with a header/footer */
                numLines = 1;
@@ -1037,8 +1034,9 @@ char *log_format_log_line(
        /* this is an upper bound--newlines in message may be counted
         * extraneously
         */
-       bufferSize = (numLines * (pre_color_prefix_len + prefixLen + post_color_prefix_len
-                       + pre_color_suffix_len + suffixLen + post_color_suffix_len)) + message_len + 1;
+       size_t bufferSize = (numLines * (pre_color_prefix_len + prefixLen + post_color_prefix_len
+                         + pre_color_suffix_len + suffixLen + post_color_suffix_len)) + message_len + 1;
+       char *ret;
 
        if (defaultBufferSize >= bufferSize) {
                ret = defaultBuffer;
@@ -1051,7 +1049,7 @@ char *log_format_log_line(
 
        ret[0] = '\0';       /* to start strcat off */
 
-       p = ret;
+       char *p = ret;
        pm = msg;
 
 #define SPACE_LEFT (bufferSize - ((p - ret) + 1))