Photon 2 does not tolerate with a NULL value


This works fine on Argons and Borons when the variable command is NULL:"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 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 in handling NULL pointers.

Lesson learned!

How to reproduce:

  char args[] = "test 123";"Command received: %s", args);
  char *command = strtok((char *)args, " ");"Command first part received: %s", command);
  command = strtok(NULL, " ");"Command second part received: %s", command);

  char args2[] = "test";"Command received: %s", args2);
  char *command2 = strtok((char *)args2, " ");"Command first part received: %s", command2);
  command2 = strtok(NULL, " ");

  // this crashes on a Photon 2 since command2 is NULL at this point"Command second part received: %s", command2);


That's slightly unexpected. just uses vsnprintf internally. And that should come from the newlib standard C library that we use in Device OS, which is platform independent. My guess is that it just happens to work on nRF52 because of what happens to be at address 0, but I don't know that for sure.

1 Like

Thanks for the insight.
If you think it’s worth warning folks about this, it could be added to the migration guides.

In the past we were able to modify the docs ourselves (via a PR).
Is this still the case? I couldn't find how.