diff options
author | Till Hofmann <hofmann@kbsg.rwth-aachen.de> | 2018-12-14 16:05:07 +0000 |
---|---|---|
committer | Dave Davenport <DaveDavenport@users.noreply.github.com> | 2018-12-14 17:05:07 +0100 |
commit | b77a48c628b5cd6a2c1c939e2f813542c7255030 (patch) | |
tree | 4683c42620558e97ceb4f9d0c7b29e56c163df9b /source | |
parent | 6b96ae123bd9bd0a1d13f3deebb560b45eeef80d (diff) |
tests: initialize char* in mode test (#875)
* tests: initialize char* in mode test
Currently, test_mode_result relies on undefined behavior.
The test calls mode_result, which checks whether the pointer is NULL.
However, the pointer was never initialized, so it may or may not be
NULL, depending on the compiler.
This caused a test failure on ppc64 and Fedora 28, apparently because in
this setting, gcc sets uninitialized pointers to NULL.
By initializing the pointer to the empty string, the behavior is defined
and the test passes on all architectures.
* mode: fix input pointer check in mode_result
Do not check whether *input (i.e., the char* the input points to) is
NULL, as this is valid. Instead, check whether the input itself is NULL.
* tests: make char* input arg in test_mode_result modifiable
The function mode_result expects a modifiable char*, initialize the
argument properly so it can be modified.
Diffstat (limited to 'source')
-rw-r--r-- | source/mode.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/source/mode.c b/source/mode.c index 28552e11..45d651a2 100644 --- a/source/mode.c +++ b/source/mode.c @@ -98,7 +98,7 @@ ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int sel { g_assert ( mode != NULL ); g_assert ( mode->_result != NULL ); - g_assert ( ( *input ) != NULL ); + g_assert ( input != NULL ); return mode->_result ( mode, menu_retv, input, selected_line ); } |