lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
* [babeltrace][PATCH] fs.c: initialize the other_entry variable
@ 2020-03-11 13:25 mingli.yu
  0 siblings, 0 replies; 5+ messages in thread
From: mingli.yu @ 2020-03-11 13:25 UTC (permalink / raw)
  To: lttng-dev

From: Mingli Yu <mingli.yu@windriver.com>

Initialize the pointer other_entry to fix the below error:
| ../../../../../git/src/plugins/ctf/fs-src/fs.c: In function 'ds_index_insert_ds_index_entry_sorted':
| ../../../../../git/src/plugins/ctf/fs-src/fs.c:702:5: error: 'other_entry' may be used uninitialized in this function [-Werror=maybe-uninitialized]
|  702 |    !ds_index_entries_equal(entry, other_entry)) {

Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
---
 src/plugins/ctf/fs-src/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c
index e87523a..a6b5315 100644
--- a/src/plugins/ctf/fs-src/fs.c
+++ b/src/plugins/ctf/fs-src/fs.c
@@ -680,7 +680,7 @@ void ds_index_insert_ds_index_entry_sorted(
 	struct ctf_fs_ds_index_entry *entry)
 {
 	guint i;
-	struct ctf_fs_ds_index_entry *other_entry;
+	struct ctf_fs_ds_index_entry *other_entry = NULL;
 
 	/* Find the spot where to insert this index entry. */
 	for (i = 0; i < index->entries->len; i++) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [babeltrace][PATCH] fs.c: initialize the other_entry variable
  2020-03-11 13:52 ` Simon Marchi
@ 2020-03-12  3:37   ` Yu, Mingli via lttng-dev
  0 siblings, 0 replies; 5+ messages in thread
From: Yu, Mingli via lttng-dev @ 2020-03-12  3:37 UTC (permalink / raw)
  To: Simon Marchi, lttng-dev

Hi Simon,

The compiler: GCC 9.2.0
The error can occur when additionally add " -Og".

Thanks,
Mingli
________________________________________
From: Simon Marchi [simark@simark.ca]
Sent: Wednesday, March 11, 2020 9:52 PM
To: Yu, Mingli; lttng-dev@lists.lttng.org
Subject: Re: [lttng-dev] [babeltrace][PATCH] fs.c: initialize the other_entry variable

On 2020-03-11 9:39 a.m., mingli.yu@windriver.com wrote:
> From: Mingli Yu <mingli.yu@windriver.com>
>
> Initialize the pointer other_entry to fix the below error:
> | ../../../../../git/src/plugins/ctf/fs-src/fs.c: In function 'ds_index_insert_ds_index_entry_sorted':
> | ../../../../../git/src/plugins/ctf/fs-src/fs.c:702:5: error: 'other_entry' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> |  702 |    !ds_index_entries_equal(entry, other_entry)) {
>
> Signed-off-by: Mingli Yu <mingli.yu@windriver.com>

Hi Mingli,

Thanks for the patch.  Could you please mention the compiler you are using
(which architecture and which version), as well as the full command line
used to compile that file (shown with "make V=1"?

Thank you,

Simon

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [babeltrace][PATCH] fs.c: initialize the other_entry variable
  2020-03-11 13:39 mingli.yu
  2020-03-11 13:52 ` Simon Marchi
@ 2020-03-11 13:58 ` Mathieu Desnoyers
  1 sibling, 0 replies; 5+ messages in thread
From: Mathieu Desnoyers @ 2020-03-11 13:58 UTC (permalink / raw)
  To: mingli yu; +Cc: lttng-dev

----- On Mar 11, 2020, at 9:39 AM, mingli yu mingli.yu@windriver.com wrote:

> From: Mingli Yu <mingli.yu@windriver.com>
> 
> Initialize the pointer other_entry to fix the below error:
>| ../../../../../git/src/plugins/ctf/fs-src/fs.c: In function
>| 'ds_index_insert_ds_index_entry_sorted':
>| ../../../../../git/src/plugins/ctf/fs-src/fs.c:702:5: error: 'other_entry' may
>| be used uninitialized in this function [-Werror=maybe-uninitialized]
>|  702 |    !ds_index_entries_equal(entry, other_entry)) {

It would be good that the commit message documents that the purpose of this
change is only to silence compiler warnings (which is indeed a good thing to
do).

It does not seem to ever be possible to reach a situation where the
uninitialized value is used, because the only case which can leave
this variable uninitialized is if index->entries->len == 0, which means
the "if (i == index->entries->len ||" will be taken (true), which will
therefore skip the second sub-expression of the if:
"!ds_index_entries_equal(entry, other_entry)", which is the only place
where "other_entry" is read.

Thanks,

Mathieu

> 
> Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
> ---
> src/plugins/ctf/fs-src/fs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c
> index e87523a..a6b5315 100644
> --- a/src/plugins/ctf/fs-src/fs.c
> +++ b/src/plugins/ctf/fs-src/fs.c
> @@ -680,7 +680,7 @@ void ds_index_insert_ds_index_entry_sorted(
> 	struct ctf_fs_ds_index_entry *entry)
> {
> 	guint i;
> -	struct ctf_fs_ds_index_entry *other_entry;
> +	struct ctf_fs_ds_index_entry *other_entry = NULL;
> 
> 	/* Find the spot where to insert this index entry. */
> 	for (i = 0; i < index->entries->len; i++) {
> --
> 2.7.4
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [babeltrace][PATCH] fs.c: initialize the other_entry variable
  2020-03-11 13:39 mingli.yu
@ 2020-03-11 13:52 ` Simon Marchi
  2020-03-12  3:37   ` Yu, Mingli via lttng-dev
  2020-03-11 13:58 ` Mathieu Desnoyers
  1 sibling, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2020-03-11 13:52 UTC (permalink / raw)
  To: mingli.yu, lttng-dev

On 2020-03-11 9:39 a.m., mingli.yu@windriver.com wrote:
> From: Mingli Yu <mingli.yu@windriver.com>
> 
> Initialize the pointer other_entry to fix the below error:
> | ../../../../../git/src/plugins/ctf/fs-src/fs.c: In function 'ds_index_insert_ds_index_entry_sorted':
> | ../../../../../git/src/plugins/ctf/fs-src/fs.c:702:5: error: 'other_entry' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> |  702 |    !ds_index_entries_equal(entry, other_entry)) {
> 
> Signed-off-by: Mingli Yu <mingli.yu@windriver.com>

Hi Mingli,

Thanks for the patch.  Could you please mention the compiler you are using
(which architecture and which version), as well as the full command line
used to compile that file (shown with "make V=1"?

Thank you,

Simon

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [babeltrace][PATCH] fs.c: initialize the other_entry variable
@ 2020-03-11 13:39 mingli.yu
  2020-03-11 13:52 ` Simon Marchi
  2020-03-11 13:58 ` Mathieu Desnoyers
  0 siblings, 2 replies; 5+ messages in thread
From: mingli.yu @ 2020-03-11 13:39 UTC (permalink / raw)
  To: lttng-dev

From: Mingli Yu <mingli.yu@windriver.com>

Initialize the pointer other_entry to fix the below error:
| ../../../../../git/src/plugins/ctf/fs-src/fs.c: In function 'ds_index_insert_ds_index_entry_sorted':
| ../../../../../git/src/plugins/ctf/fs-src/fs.c:702:5: error: 'other_entry' may be used uninitialized in this function [-Werror=maybe-uninitialized]
|  702 |    !ds_index_entries_equal(entry, other_entry)) {

Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
---
 src/plugins/ctf/fs-src/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c
index e87523a..a6b5315 100644
--- a/src/plugins/ctf/fs-src/fs.c
+++ b/src/plugins/ctf/fs-src/fs.c
@@ -680,7 +680,7 @@ void ds_index_insert_ds_index_entry_sorted(
 	struct ctf_fs_ds_index_entry *entry)
 {
 	guint i;
-	struct ctf_fs_ds_index_entry *other_entry;
+	struct ctf_fs_ds_index_entry *other_entry = NULL;
 
 	/* Find the spot where to insert this index entry. */
 	for (i = 0; i < index->entries->len; i++) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-12  4:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 13:25 [babeltrace][PATCH] fs.c: initialize the other_entry variable mingli.yu
2020-03-11 13:39 mingli.yu
2020-03-11 13:52 ` Simon Marchi
2020-03-12  3:37   ` Yu, Mingli via lttng-dev
2020-03-11 13:58 ` Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).