[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fix uninitialized variables when Source_file::get_counts returns early d
From: |
reinhold . kainhofer |
Subject: |
Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047) |
Date: |
Tue, 23 Aug 2011 11:14:06 +0000 |
Reviewers: ,
Message:
Please review to get rid of some uninitialized variables.
Description:
Fix uninitialized variables when Source_file::get_counts returns early
due to !contains (pos_str0)
Most code that called get_counts simply is like:
int line, chr, col, offset = 0;
source_file_->get_counts (end_, &line, &chr, &col, &offset);
Now, unfortunately get_counts returns early sometimes (if we don't have
a position), so
only line_number would be initialized to 0, all other variables would
stay uninitialized.
And most code simply passed them on to other guile functions to handle.
This patch moved the initialization of all arguments to the very
beginning of get_counts
and thus never returns uninizialized variables.
This shuts up several valgrind warnings in our regtests.
Please review this at http://codereview.appspot.com/4940047/
Affected files:
M lily/source-file.cc
Index: lily/source-file.cc
diff --git a/lily/source-file.cc b/lily/source-file.cc
index
b42fb7a5b37a508f69ce8d31925ae9478e7972c4..041c046d2bfc2fa4761df56005f2e76692f962f7
100644
--- a/lily/source-file.cc
+++ b/lily/source-file.cc
@@ -261,7 +261,11 @@ Source_file::get_counts (char const *pos_str0,
int *column,
int *byte_offset) const
{
+ // Initialize arguments to defaults, needed if pos_str0 is not in source
*line_number = 0;
+ *line_char = 0;
+ *column = 0;
+ *byte_offset = 0;
if (!contains (pos_str0))
return;
@@ -276,10 +280,6 @@ Source_file::get_counts (char const *pos_str0,
string line_begin (line_start, left);
char const *line_chars = line_begin.c_str ();
- *line_char = 0;
- *column = 0;
- *byte_offset = 0;
-
while (left > 0)
{
size_t thislen = utf8_char_len (*line_chars);
- Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047),
reinhold . kainhofer <=
- Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047), Carl . D . Sorensen, 2011/08/23
- Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047), ianhulin44, 2011/08/23
- Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047), Graham Percival, 2011/08/23
- Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047), Carl Sorensen, 2011/08/23
- Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047), Ian Hulin, 2011/08/24
- Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047), David Kastrup, 2011/08/24
- Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047), Reinhold Kainhofer, 2011/08/24
- Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047), Dan Eble, 2011/08/24
- Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047), David Kastrup, 2011/08/24