[F] Fix undefined behavior due to incorrect usage of isprint
This commit is contained in:
Seleznev Anton 2019-11-28 21:31:28 +03:00 committed by GitHub
commit 5731d45ae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 15 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(libfort VERSION 0.3.1) project(libfort VERSION 0.3.2)
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)"
"\\1.\\2" libfort_SOVERSION "\\1.\\2" libfort_SOVERSION

View File

@ -1,3 +1,9 @@
## v0.3.2
### Bug fixes
- Fix undefined behavior due to incorrect usage of `isprint` function.
## v0.3.1 ## v0.3.1
### Bug fixes ### Bug fixes

View File

@ -2582,7 +2582,6 @@ SOFTWARE.
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <wchar.h> #include <wchar.h>
#include <ctype.h>
/* #include "vector.h" */ /* Commented by amalgamation script */ /* #include "vector.h" */ /* Commented by amalgamation script */
/* #include "fort_utils.h" */ /* Commented by amalgamation script */ /* #include "fort_utils.h" */ /* Commented by amalgamation script */
@ -5416,10 +5415,14 @@ int print_row_separator_impl(f_conv_context_t *cntx,
size_t i = 0; size_t i = 0;
/* If all chars are not printable, skip line separator */ /* If all chars are not printable, skip line separator */
if ((strlen(*L) == 0 || (strlen(*L) == 1 && !isprint(**L))) /* NOTE: argument of `isprint` should be explicitly converted to
&& (strlen(*I) == 0 || (strlen(*I) == 1 && !isprint(**I))) * unsigned char according to
&& (strlen(*IV) == 0 || (strlen(*IV) == 1 && !isprint(**IV))) * https://en.cppreference.com/w/c/string/byte/isprint
&& (strlen(*R) == 0 || (strlen(*R) == 1 && !isprint(**R)))) { */
if ((strlen(*L) == 0 || (strlen(*L) == 1 && !isprint((unsigned char) **L)))
&& (strlen(*I) == 0 || (strlen(*I) == 1 && !isprint((unsigned char) **I)))
&& (strlen(*IV) == 0 || (strlen(*IV) == 1 && !isprint((unsigned char) **IV)))
&& (strlen(*R) == 0 || (strlen(*R) == 1 && !isprint((unsigned char) **R)))) {
status = 0; status = 0;
goto clear; goto clear;
} }

View File

@ -46,8 +46,8 @@ SOFTWARE.
#define LIBFORT_MAJOR_VERSION 0 #define LIBFORT_MAJOR_VERSION 0
#define LIBFORT_MINOR_VERSION 3 #define LIBFORT_MINOR_VERSION 3
#define LIBFORT_REVISION 0 #define LIBFORT_REVISION 2
#define LIBFORT_VERSION_STR "0.3.0" #define LIBFORT_VERSION_STR "0.3.2"
/***************************************************************************** /*****************************************************************************

View File

@ -46,8 +46,8 @@ SOFTWARE.
#define LIBFORT_MAJOR_VERSION 0 #define LIBFORT_MAJOR_VERSION 0
#define LIBFORT_MINOR_VERSION 3 #define LIBFORT_MINOR_VERSION 3
#define LIBFORT_REVISION 1 #define LIBFORT_REVISION 2
#define LIBFORT_VERSION_STR "0.3.1" #define LIBFORT_VERSION_STR "0.3.2"
/***************************************************************************** /*****************************************************************************

View File

@ -31,7 +31,6 @@ SOFTWARE.
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <wchar.h> #include <wchar.h>
#include <ctype.h>
#include "vector.h" #include "vector.h"
#include "fort_utils.h" #include "fort_utils.h"

View File

@ -353,10 +353,14 @@ int print_row_separator_impl(f_conv_context_t *cntx,
size_t i = 0; size_t i = 0;
/* If all chars are not printable, skip line separator */ /* If all chars are not printable, skip line separator */
if ((strlen(*L) == 0 || (strlen(*L) == 1 && !isprint(**L))) /* NOTE: argument of `isprint` should be explicitly converted to
&& (strlen(*I) == 0 || (strlen(*I) == 1 && !isprint(**I))) * unsigned char according to
&& (strlen(*IV) == 0 || (strlen(*IV) == 1 && !isprint(**IV))) * https://en.cppreference.com/w/c/string/byte/isprint
&& (strlen(*R) == 0 || (strlen(*R) == 1 && !isprint(**R)))) { */
if ((strlen(*L) == 0 || (strlen(*L) == 1 && !isprint((unsigned char) **L)))
&& (strlen(*I) == 0 || (strlen(*I) == 1 && !isprint((unsigned char) **I)))
&& (strlen(*IV) == 0 || (strlen(*IV) == 1 && !isprint((unsigned char) **IV)))
&& (strlen(*R) == 0 || (strlen(*R) == 1 && !isprint((unsigned char) **R)))) {
status = 0; status = 0;
goto clear; goto clear;
} }