Skip to content

Commit ffd0e3a

Browse files
committed
broadcom/compiler: fix coverity warning (unitialized pointer read)
Full coverity warning: CID 1558604: Uninitialized pointer read (UNINIT)12. uninit_use_in_call: Using uninitialized value *results when calling nir_vec. 236 return nir_vec(b, results, DIV_ROUND_UP(num_components, 2)); To fix it we initialize the variables, provide a unreachable on the switch that sets the results values. As we are here we also move a comment to make things more clear. Reviewed-by: Juan A. Suarez <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26951>
1 parent f2b7c4c commit ffd0e3a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/broadcom/compiler/v3d_nir_lower_image_load_store.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,8 @@ pack_16bit(nir_builder *b, nir_def *color,
199199
unsigned num_components,
200200
enum hw_conversion conversion)
201201
{
202-
nir_def *results[2];
203-
nir_def *channels[4];
204-
205-
/* Note that usually you should not use this method (that relies on
206-
* custom packing) if we are not doing any conversion. But we support
207-
* also that case, and let the caller decide which method to use.
208-
*/
202+
nir_def *results[2] = {0};
203+
nir_def *channels[4] = {0};
209204

210205
for (unsigned i = 0; i < num_components; i++) {
211206
channels[i] = nir_channel(b, color, i);
@@ -217,6 +212,11 @@ pack_16bit(nir_builder *b, nir_def *color,
217212
channels[i] = nir_f2unorm_16_v3d(b, channels[i]);
218213
break;
219214
default:
215+
/* Note that usually you should not use this method
216+
* (that relies on custom packing) if we are not doing
217+
* any conversion. But we support also that case, and
218+
* let the caller decide which method to use.
219+
*/
220220
break;
221221
}
222222
}
@@ -231,6 +231,8 @@ pack_16bit(nir_builder *b, nir_def *color,
231231
case 2:
232232
results[0] = nir_pack_2x32_to_2x16_v3d(b, channels[0], channels[1]);
233233
break;
234+
default:
235+
unreachable("Invalid number of components");
234236
}
235237

236238
return nir_vec(b, results, DIV_ROUND_UP(num_components, 2));

0 commit comments

Comments
 (0)