Skip to content

Commit 339ca81

Browse files
authored
Fix ut-of-bounds read inside norm_inf by returning 0.0 for 0 len arrays in norm_inf, closes #284 (#285)
1 parent 911cb49 commit 339ca81

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/linalg.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ scs_float SCS(norm_inf)(const scs_float *a, scs_int len) {
153153
*/
154154

155155
scs_float SCS(norm_inf)(const scs_float *a, scs_int len) {
156+
/* Follow the semantics of BLASI(lange) for zero-size array. */
157+
scs_int idx;
156158
blas_int bone = 1;
157159
blas_int blen = (blas_int)len;
158-
scs_int idx = (scs_int)BLASI(amax)(&blen, a, &bone);
160+
if (len <= 0) {
161+
return 0.0;
162+
}
163+
idx = (scs_int)BLASI(amax)(&blen, a, &bone);
159164
/* Returned idx is 1-based. */
160165
return ABS(a[idx - 1]);
161166
}

0 commit comments

Comments
 (0)