[m-rev.] diff: Fix some uninitialised variables in error paths.
Peter Wang
novalazy at gmail.com
Thu Jul 2 16:13:53 AEST 2020
browser/util.m:
compiler/equiv_type_hlds.m:
compiler/inst_test.m:
library/construct.m:
library/io.m:
Ensure output variables are initialised in all code paths.
diff --git a/browser/util.m b/browser/util.m
index 54f4181f8..4e2bb0975 100644
--- a/browser/util.m
+++ b/browser/util.m
@@ -96,7 +96,7 @@ trace_getline(Prompt, Result, MdbIn, MdbOut, !IO) :-
% which only works for will_not_call_mercury foreign_procs.
[will_not_call_mercury, promise_pure, tabled_for_io],
"
- char *line;
+ char *line = NULL;
MercuryFile *mdb_in = (MercuryFile *) MdbIn;
MercuryFile *mdb_out = (MercuryFile *) MdbOut;
diff --git a/compiler/equiv_type_hlds.m b/compiler/equiv_type_hlds.m
index 772e2109a..f6f51a44f 100644
--- a/compiler/equiv_type_hlds.m
+++ b/compiler/equiv_type_hlds.m
@@ -1138,6 +1138,7 @@ static TypeInInstCacheEntry type_in_inst_cache[TYPE_IN_INST_CACHE_SIZE];
MayOccur = type_in_inst_cache[hash].tice_may_occur;
} else {
Found = MR_BOOL_NO;
+ MayOccur = MR_BOOL_NO;
}
").
diff --git a/compiler/inst_test.m b/compiler/inst_test.m
index 8990cad9c..472de0347 100644
--- a/compiler/inst_test.m
+++ b/compiler/inst_test.m
@@ -302,6 +302,7 @@ static InstIsGroundCacheEntry
IsGround = inst_is_ground_cache[hash].iig_is_ground;
} else {
Found = MR_BOOL_NO;
+ IsGround = MR_NO;
}
").
diff --git a/library/construct.m b/library/construct.m
index a2fca5ca1..850f9355f 100644
--- a/library/construct.m
+++ b/library/construct.m
@@ -480,7 +480,8 @@ get_functor_ordinal(TypeDesc, FunctorNumber, Ordinal) :-
case MR_TYPECTOR_REP_UNUSED2:
case MR_TYPECTOR_REP_UNKNOWN:
success = MR_FALSE;
-
+ Ordinal = 0;
+ break;
}
}
SUCCESS_INDICATOR = success;
diff --git a/library/io.m b/library/io.m
index 42f7484d9..4631357e8 100644
--- a/library/io.m
+++ b/library/io.m
@@ -6114,11 +6114,12 @@ read_char_code(input_stream(Stream), ResultCode, Char, Error, !IO) :-
if (MR_FERROR(*Stream)) {
ResultCode = ML_RESULT_CODE_ERROR;
Error = errno;
+ Char = 0;
} else {
ResultCode = ML_RESULT_CODE_EOF;
Error = 0;
+ Char = 0;
}
- Char = 0;
} else {
if ((uc & 0xE0) == 0xC0) {
nbytes = 2;
@@ -14236,24 +14237,23 @@ decode_system_command_exit_code(Code0) = Status :-
[will_not_call_mercury, thread_safe, promise_pure,
does_not_affect_liveness, no_sharing],
"
+ Exited = MR_NO;
+ Status = 0;
+ Signalled = MR_NO;
+ Signal = 0;
+
#if defined (WIFEXITED) && defined (WEXITSTATUS) && \
defined (WIFSIGNALED) && defined (WTERMSIG)
if (WIFEXITED(Status0)) {
Exited = MR_YES;
- Signalled = MR_NO;
Status = WEXITSTATUS(Status0);
} else if (WIFSIGNALED(Status0)) {
- Exited = MR_NO;
Signalled = MR_YES;
Signal = -WTERMSIG(Status0);
- } else {
- Exited = MR_NO;
- Signalled = MR_NO;
}
#else
Exited = MR_YES;
Status = Status0;
- Signalled = MR_NO;
#endif
").
--
2.27.0
More information about the reviews
mailing list