[riot-notifications] [RIOT-OS/RIOT] sys/ps: Improve robustness against string table errors. (#10977)

Juan I Carrano notifications at github.com
Mon Feb 11 11:45:57 CET 2019


jcarrano commented on this pull request.



> @@ -42,6 +43,28 @@ static const char *state_names[] = {
     [STATUS_MBOX_BLOCKED] = "bl mbox",
 };
 
+#define N_STATE_NAMES ((int)(sizeof(state_names)/sizeof(state_names[0])))
+#define UNKNOWN_STATE_NAME "unknown"
+
+/**
+ * Convert a thread state code to a human readable string.
+ *
+ * Use this function instead of a direct array lookup: if ever state_names
+ * and the actual states in tcb.h get out of sync, an invalid index can be
+ * generated, and direct access will cause a crash that this function is
+ * designed to prevent.
+ */
+const char *state_to_string(int state)

Because the thread state is an int: https://github.com/RIOT-OS/RIOT/blob/ea284ee216a5ebb1f61e54d915a8e7b4eaea2e53/sys/ps/ps.c#L120-L122

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10977#discussion_r255453548
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190211/e51576c3/attachment.html>


More information about the notifications mailing list