From 087ad4e10b28c704703c5dc873b6429cebe1b33e Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sun, 29 Jul 2018 11:24:05 +0300 Subject: [PATCH] [F] Fixed compiler warnings --- README.md | 2 +- lib/fort.c | 14 ++++++++------ src/row.c | 8 ++++---- src/string_buffer.c | 6 ++++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ac23dc7..7e1d9fa 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ [![Build Status](https://travis-ci.org/seleznevae/libfort.svg?branch=master)](https://travis-ci.org/seleznevae/libfort) [![Build status](https://ci.appveyor.com/api/projects/status/ll1qygb56pho95xw/branch/master?svg=true)](https://ci.appveyor.com/project/seleznevae/libfort/branch/master) [![Coverage Status](https://coveralls.io/repos/github/seleznevae/libfort/badge.svg?branch=master)](https://coveralls.io/github/seleznevae/libfort?branch=master) +[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/6QTaJLeXIf6mS6KN) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) - **libfort** - a simple library to create formatted ASCII tables. **libfort** is written in C language and can be used in C and C++ projects. For C++ projects that use compiler with c++11 support there are also availabe convenient c++ wrappers around c functions (see **fort.hpp** in **lib** direrctory). **Features:** diff --git a/lib/fort.c b/lib/fort.c index 53e684a..161ed28 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -3092,6 +3092,7 @@ int buffer_printf(string_buffer_t *buffer, size_t buffer_row, char *buf, size_t int written = 0; int tmp = 0; + ptrdiff_t str_it_width = 0; const CHAR_TYPE *beg = NULL; const CHAR_TYPE *end = NULL; CHAR_TYPE old_value; @@ -3104,7 +3105,7 @@ int buffer_printf(string_buffer_t *buffer, size_t buffer_row, char *buf, size_t old_value = *end; *(CHAR_TYPE *)end = NULL_CHAR; - ptrdiff_t str_it_width = STR_ITER_WIDTH(beg, end); + str_it_width = STR_ITER_WIDTH(beg, end); if (str_it_width < 0 || content_width < (size_t)str_it_width) return - 1; @@ -3177,6 +3178,7 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, wchar_t *buf, siz int written = 0; int tmp = 0; + ptrdiff_t str_it_width = 0; const CHAR_TYPE *beg = NULL; const CHAR_TYPE *end = NULL; CHAR_TYPE old_value; @@ -3189,7 +3191,7 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, wchar_t *buf, siz old_value = *end; *(CHAR_TYPE *)end = NULL_CHAR; - ptrdiff_t str_it_width = STR_ITER_WIDTH(beg, end); + str_it_width = STR_ITER_WIDTH(beg, end); if (str_it_width < 0 || content_width < (size_t)str_it_width) return - 1; @@ -3835,6 +3837,8 @@ int print_row_separator(char *buffer, size_t buffer_sz, } } + size_t i = 0; + /* If all chars are not printable, skip line separator */ /* todo: add processing for wchar_t */ // if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { // status = 0; @@ -3848,8 +3852,6 @@ int print_row_separator(char *buffer, size_t buffer_sz, goto clear; } - size_t i = 0; - /* Print left margin */ CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.left_margin, space_char)); @@ -4008,6 +4010,8 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, } } + size_t i = 0; + /* If all chars are not printable, skip line separator */ /* todo: add processing for wchar_t */ // if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { // status = 0; @@ -4021,8 +4025,6 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, goto clear; } - size_t i = 0; - /* Print left margin */ CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.left_margin, space_char)); diff --git a/src/row.c b/src/row.c index bafee6d..4bd41aa 100644 --- a/src/row.c +++ b/src/row.c @@ -313,6 +313,8 @@ int print_row_separator(char *buffer, size_t buffer_sz, } } + size_t i = 0; + /* If all chars are not printable, skip line separator */ /* todo: add processing for wchar_t */ // if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { // status = 0; @@ -326,8 +328,6 @@ int print_row_separator(char *buffer, size_t buffer_sz, goto clear; } - size_t i = 0; - /* Print left margin */ CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.left_margin, space_char)); @@ -486,6 +486,8 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, } } + size_t i = 0; + /* If all chars are not printable, skip line separator */ /* todo: add processing for wchar_t */ // if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { // status = 0; @@ -499,8 +501,6 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, goto clear; } - size_t i = 0; - /* Print left margin */ CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.left_margin, space_char)); diff --git a/src/string_buffer.c b/src/string_buffer.c index 5064ddd..56382cc 100644 --- a/src/string_buffer.c +++ b/src/string_buffer.c @@ -326,6 +326,7 @@ int buffer_printf(string_buffer_t *buffer, size_t buffer_row, char *buf, size_t int written = 0; int tmp = 0; + ptrdiff_t str_it_width = 0; const CHAR_TYPE *beg = NULL; const CHAR_TYPE *end = NULL; CHAR_TYPE old_value; @@ -338,7 +339,7 @@ int buffer_printf(string_buffer_t *buffer, size_t buffer_row, char *buf, size_t old_value = *end; *(CHAR_TYPE *)end = NULL_CHAR; - ptrdiff_t str_it_width = STR_ITER_WIDTH(beg, end); + str_it_width = STR_ITER_WIDTH(beg, end); if (str_it_width < 0 || content_width < (size_t)str_it_width) return - 1; @@ -411,6 +412,7 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, wchar_t *buf, siz int written = 0; int tmp = 0; + ptrdiff_t str_it_width = 0; const CHAR_TYPE *beg = NULL; const CHAR_TYPE *end = NULL; CHAR_TYPE old_value; @@ -423,7 +425,7 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, wchar_t *buf, siz old_value = *end; *(CHAR_TYPE *)end = NULL_CHAR; - ptrdiff_t str_it_width = STR_ITER_WIDTH(beg, end); + str_it_width = STR_ITER_WIDTH(beg, end); if (str_it_width < 0 || content_width < (size_t)str_it_width) return - 1;