Skip to content

Commit a83d4e0

Browse files
jlamaandypugh
authored andcommitted
hal_stream_create: fix bogus error check
hal_stream_create() did not check the return value of halpr_parse_types() properly, so the stream could be created with any kind of invalid cfg string.
1 parent 29f006a commit a83d4e0

5 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/hal/hal_lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3984,7 +3984,7 @@ int hal_stream_create(hal_stream_t *stream, int comp, int key, int depth, const
39843984
int result = 0;
39853985
hal_type_t type[HAL_STREAM_MAX_PINS];
39863986
result = halpr_parse_types(type, typestring);
3987-
if(result < 0) return result;
3987+
if(!result) return -EINVAL;
39883988
int pin_count = result;
39893989

39903990
size_t size = sizeof(struct hal_stream_shm) + sizeof(union hal_stream_data) * depth * (1+pin_count);

tests/hal-stream/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Creating a hal stream should fail if the cfg string is invalid.

tests/hal-stream/expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pass

tests/hal-stream/test.hal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
loadusr -w ./test.py

tests/hal-stream/test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python3
2+
import hal
3+
4+
c = hal.component("stream_test")
5+
try:
6+
writer = hal.stream(c, hal.streamer_base, 10, "xx")
7+
except:
8+
pass
9+
else:
10+
assert False, "hal.stream should fail with invalid cfg arg"
11+
12+
c.ready()
13+
print("pass")

0 commit comments

Comments
 (0)