technoblogy / ulisp-esp

A version of the Lisp programming language for ESP32-based boards.
MIT License
110 stars 37 forks source link

weird edge case crash in `(restart-i2c)` #76

Closed dragoncoder047 closed 1 year ago

dragoncoder047 commented 1 year ago

Somehow I managed to hit a weird edge case in (restart-i2c) -- it segfaults if stream is nil. You'd never think that could happen but it did.

Fix:

object *fn_restarti2c (object *args, object *env) {
  (void) env;
- int stream = first(args)->integer;
+ int stream = isstream(first(args));
  args = cdr(args);
  int read = 0; // Write
  I2Ccount = 0;
  if (args != NULL) {
    object *rw = first(args);
    if (integerp(rw)) I2Ccount = rw->integer;
    read = (rw != NULL);
  }
  int address = stream & 0xFF;
  if (stream>>8 != I2CSTREAM) error2(PSTR("not an i2c stream"));
  return I2Crestart(address, read) ? tee : nil;
}
technoblogy commented 1 year ago

Good find - I'll fix that.