You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @mcuadros. A while back I blindly submitted a PR which I prepared in my head. My idea was to catch panics which were caused by an invalid config or not running as root. But I just noticed that this doesn't work as expected.
m:=C.led_matrix_create_from_options(config.toC(), nil, nil)
b:=C.led_matrix_create_offscreen_canvas(m)
// Some other code ...ifm==nil {
returnnil, fmt.Errorf("unable to allocate memory")
}
If the application is not running as root, m will benil. Why this case is handled, m is still passed to b := C.led_matrix_create_offscreen_canvas(m) without checking that m is not nil! This causes the panic.
A simple solution could look like this:
m:=C.led_matrix_create_from_options(config.toC(), nil, nil)
ifm==nil {
returnnil, fmt.Errorf("unable to allocate memory for matrix")
}
b:=C.led_matrix_create_offscreen_canvas(m)
ifb==nil {
returnnil, fmt.Errorf("unable to allocate memory for offscreen canvas")
}
// Do some other stuff ...
Feel free to suggest a different solution or drop me line if you want me to prepare a PR.
The text was updated successfully, but these errors were encountered:
jcrd
added a commit
to jcrd/go-rpi-rgb-led-matrix
that referenced
this issue
Mar 9, 2021
Hi @mcuadros. A while back I blindly submitted a PR which I prepared in my head. My idea was to catch panics which were caused by an invalid config or not running as root. But I just noticed that this doesn't work as expected.
The reason why the code panics is located in these two lines.
If the application is not running as root,
m
will benil
. Why this case is handled,m
is still passed tob := C.led_matrix_create_offscreen_canvas(m)
without checking thatm
is notnil
! This causes the panic.A simple solution could look like this:
Feel free to suggest a different solution or drop me line if you want me to prepare a PR.
The text was updated successfully, but these errors were encountered: