@@ -131,7 +131,6 @@ static int subkey_to_variant(struct cfl_variant *vobj, struct mk_list *subkeys,
131
131
{
132
132
int levels ;
133
133
int matched = 0 ;
134
- cfl_sds_t found = NULL ;
135
134
cfl_sds_t key = NULL ;
136
135
struct cfl_variant * val = NULL ;
137
136
struct cfl_kvpair * kvpair = NULL ;
@@ -142,6 +141,11 @@ static int subkey_to_variant(struct cfl_variant *vobj, struct mk_list *subkeys,
142
141
/* Expected number of map levels in the map */
143
142
levels = mk_list_size (subkeys );
144
143
144
+ /* Early return if no subkeys */
145
+ if (levels == 0 ) {
146
+ return -1 ;
147
+ }
148
+
145
149
cur = * vobj ;
146
150
147
151
mk_list_foreach (head , subkeys ) {
@@ -157,14 +161,20 @@ static int subkey_to_variant(struct cfl_variant *vobj, struct mk_list *subkeys,
157
161
158
162
/* Index limit and ensure no overflow */
159
163
if (entry -> array_id == INT_MAX ||
160
- cfl_array_size (cur .data .as_array ) < entry -> array_id + 1 ) {
164
+ entry -> array_id >= cfl_array_size (cur .data .as_array )) {
161
165
return -1 ;
162
166
}
163
167
164
168
val = cur .data .as_array -> entries [entry -> array_id ];
165
169
cur = * val ;
166
170
key = NULL ; /* fill NULL since the type is array. */
167
- goto next ;
171
+ matched ++ ;
172
+
173
+ if (levels == matched ) {
174
+ break ;
175
+ }
176
+
177
+ continue ;
168
178
}
169
179
170
180
if (cur .type != CFL_VARIANT_KVLIST ) {
@@ -173,17 +183,13 @@ static int subkey_to_variant(struct cfl_variant *vobj, struct mk_list *subkeys,
173
183
174
184
kvpair = cfl_variant_kvpair_get (& cur , entry -> str );
175
185
if (kvpair == NULL ) {
176
- found = NULL ;
177
- continue ;
186
+ continue ; /* Try next entry */
178
187
}
179
188
180
189
key = kvpair -> key ;
181
190
val = kvpair -> val ;
182
191
183
- found = key ;
184
192
cur = * val ;
185
-
186
- next :
187
193
matched ++ ;
188
194
189
195
if (levels == matched ) {
@@ -192,7 +198,7 @@ static int subkey_to_variant(struct cfl_variant *vobj, struct mk_list *subkeys,
192
198
}
193
199
194
200
/* No matches */
195
- if (found == NULL || (matched > 0 && levels != matched )) {
201
+ if (matched == 0 || (matched > 0 && levels != matched )) {
196
202
return -1 ;
197
203
}
198
204
@@ -202,7 +208,6 @@ static int subkey_to_variant(struct cfl_variant *vobj, struct mk_list *subkeys,
202
208
return 0 ;
203
209
}
204
210
205
-
206
211
struct flb_cfl_ra_value * flb_cfl_ra_key_to_value (flb_sds_t ckey ,
207
212
struct cfl_variant vobj ,
208
213
struct mk_list * subkeys )
0 commit comments