* [PATCH v2] libtraceeval: Fix comparing unsigned against zero
@ 2023-10-03 13:10 Steven Rostedt
2023-10-03 15:19 ` Ross Zwisler
0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2023-10-03 13:10 UTC (permalink / raw)
To: Linux Trace Devel; +Cc: Ross Zwisler, Stevie Alvarez
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
nr_key_types and nr_val_types are both size_t which is an unsized number.
A compare against zero is always false:
if (teval->nr_key_types < 0)
Change them to ssize_t (signed type).
Also change the few places the "size_t i" is used where it does:
for (; i >= 0; i--)
as that too needs to be signed to work.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Changes since v1: https://lore.kernel.org/linux-trace-devel/20230927041629.43ffbfd9@rorschach.local.home
- Use ssize_t type instead of typecasting (Ross Zwisler)
src/eval-local.h | 4 ++--
src/histograms.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/eval-local.h b/src/eval-local.h
index 5c3918f17cc1..f7a9de4628ba 100644
--- a/src/eval-local.h
+++ b/src/eval-local.h
@@ -66,8 +66,8 @@ struct traceeval {
struct traceeval_type *key_types;
struct traceeval_type *val_types;
struct hash_table *hist;
- size_t nr_key_types;
- size_t nr_val_types;
+ ssize_t nr_key_types;
+ ssize_t nr_val_types;
};
struct traceeval_iterator {
diff --git a/src/histograms.c b/src/histograms.c
index 96f0926f062c..9f9594aa9546 100644
--- a/src/histograms.c
+++ b/src/histograms.c
@@ -159,7 +159,7 @@ static size_t type_alloc(const struct traceeval_type *defs,
{
struct traceeval_type *new_defs = NULL;
size_t size;
- size_t i;
+ ssize_t i;
*copy = NULL;
@@ -196,7 +196,7 @@ fail:
else
print_err("traceeval_type list missing a name");
- for (; i >=0; i--)
+ for (; i >= 0; i--)
free(new_defs[i].name);
free(new_defs);
return -1;
@@ -785,7 +785,7 @@ static int update_entry(struct traceeval *teval, struct entry *entry,
union traceeval_data *copy = entry->vals;
union traceeval_data old[teval->nr_val_types];
size_t size = teval->nr_val_types;
- size_t i;
+ ssize_t i;
if (!size)
return 0;
--
2.40.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] libtraceeval: Fix comparing unsigned against zero
2023-10-03 13:10 [PATCH v2] libtraceeval: Fix comparing unsigned against zero Steven Rostedt
@ 2023-10-03 15:19 ` Ross Zwisler
0 siblings, 0 replies; 2+ messages in thread
From: Ross Zwisler @ 2023-10-03 15:19 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Linux Trace Devel, Stevie Alvarez
On Tue, Oct 03, 2023 at 09:10:32AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
>
> nr_key_types and nr_val_types are both size_t which is an unsized number.
> A compare against zero is always false:
>
> if (teval->nr_key_types < 0)
>
> Change them to ssize_t (signed type).
>
> Also change the few places the "size_t i" is used where it does:
>
> for (; i >= 0; i--)
>
> as that too needs to be signed to work.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Reviewed-by: Ross Zwisler <zwisler@google.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-03 15:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-03 13:10 [PATCH v2] libtraceeval: Fix comparing unsigned against zero Steven Rostedt
2023-10-03 15:19 ` Ross Zwisler
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).