Skip to contentSkip to conversation

Initialize field_size prior to use

PATCH In review Ian Rogers 2 participants 2 messages Sep 28, 2022

lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 Initialize field_size prior to use

Building with CC=clang yields:

```
  COMPILE FPIC       event-parse.o
event-parse.c:4313:17: warning: variable 'field_size' is uninitialized when used here [-Wuninitialized]
                                           offset, field_size)) {
                                                   ^~~~~~~~~~
event-parse.c:4108:25: note: initialize the variable 'field_size' to silence this warning
        unsigned int field_size;
                               ^
                                = 0
1 warning generated.
```

dynamic_offset_field will compute the length of the field and so use that to give field_size a legitimate value.

---
 src/event-parse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/event-parse.c +1 -1
index 980e980..b3e0ea7 100644
@@ -4308,7 +4308,7 @@ eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg
 	case TEP_PRINT_DYNAMIC_ARRAY:
 		/* Without [], we pass the address to the dynamic data */
 		dynamic_offset_field(tep, arg->dynarray.field, data, size,
-				     &offset, NULL);
+				     &offset, &field_size);
 		if (check_data_offset_size(event, arg->field.name, size,
 					   offset, field_size)) {
 			val = (unsigned long)data;
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
#1 lore raw
Quoted 14 lines · On Wed, 28 Sep 2022 14:09:31 -0700 Ian Rogers <[email protected]> wrote:

Building with CC=clang yields:

```
  COMPILE FPIC       event-parse.o
event-parse.c:4313:17: warning: variable 'field_size' is uninitialized when used here [-Wuninitialized]
                                           offset, field_size)) {
                                                   ^~~~~~~~~~
event-parse.c:4108:25: note: initialize the variable 'field_size' to silence this warning
        unsigned int field_size;
                               ^
                                = 0
1 warning generated.
```
Quoted 2 lines

dynamic_offset_field will compute the length of the field and so use that to give field_size a legitimate value.

Actually the field_size is not needed here.

I have a patch pending to fix this:

https://patchwork.kernel.org/project/linux-trace-devel/patch/[email protected]/

-- Steve

Quoted 19 lines
---
 src/event-parse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/event-parse.c +1 -1
index 980e980..b3e0ea7 100644
@@ -4308,7 +4308,7 @@ eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg
 	case TEP_PRINT_DYNAMIC_ARRAY:
 		/* Without [], we pass the address to the dynamic data */
 		dynamic_offset_field(tep, arg->dynarray.field, data, size,
-				     &offset, NULL);
+				     &offset, &field_size);
 		if (check_data_offset_size(event, arg->field.name, size,
 					   offset, field_size)) {
 			val = (unsigned long)data;