fix logging: out-of-bounds check should end with user categories

To check category bounds, rather use num_cat_user, to redirect all semantically
unknown categories to DLGLOBAL.

Adjust logging_test expectations accordingly: "(d)" is now also shown.

Note: subsys is and needs to be signed, while num_cat* are unsigned. Thus for a
negative subsys, 'subsys >= num_cat_user' practically always yields true. Pay
close attention to signedness and check upper bound only for positive values.

Change-Id: I4a952b759f30d90fbfb81fedcfc56a8092ea18c1
diff --git a/src/logging.c b/src/logging.c
index 2a8bfdc..d32ca43 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -336,6 +336,11 @@
  * which should never happen unless even the DLGLOBAL category is missing. */
 static inline int map_subsys(int subsys)
 {
+	/* Note: comparing signed and unsigned integers */
+
+	if (subsys > 0 && ((unsigned int)subsys) >= osmo_log_info->num_cat_user)
+		subsys = DLGLOBAL;
+
 	if (subsys < 0)
 		subsys = subsys_lib2index(subsys);