Hey,
This works fine on Argons and Borons when the variable command is NULL:
Log.info("test: %s", command);
But it does not work well on Photon 2 (5.8.2 and potentially other deviceOS versions).
AI was quick to flag this as a potential red flag:
Logging Pointers: Ensure that Log.info can handle NULL
pointers gracefully, as logging NULL might cause issues
in some logging implementations.
Of course, these issues can (and should) be avoided in code, but I realize now that I was relying too much on the leniency of Log.info()
in handling NULL
pointers.
Lesson learned!
How to reproduce:
char args[] = "test 123";
Log.info("Command received: %s", args);
char *command = strtok((char *)args, " ");
Log.info("Command first part received: %s", command);
command = strtok(NULL, " ");
Log.info("Command second part received: %s", command);
char args2[] = "test";
Log.info("Command received: %s", args2);
char *command2 = strtok((char *)args2, " ");
Log.info("Command first part received: %s", command2);
command2 = strtok(NULL, " ");
// this crashes on a Photon 2 since command2 is NULL at this point
Log.info("Command second part received: %s", command2);