fix two potential null pointer exception
authorLaurent Mazet <mazet@softndesign.org>
Fri, 11 Apr 2025 21:57:40 +0000 (23:57 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 11 Apr 2025 21:57:40 +0000 (23:57 +0200)
makefile
morep_simulator.c

index 02337374ac87b0cf259d30ab3f5c8efce61373ce..f9e2c4750be6998131a93b89b32f93bb525706f9 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,6 +1,6 @@
 # Default flags
 
-CC = gcc
+CC ?= gcc
 
 #INCLUDES = -I../debug -D__MEMORY_ALLOCATION__
 INCLUDES += -DVERBOSE_COLOR=1
index cc5237d43513c78a4830df46fd2050e627e8aa97..f7b198986dd8f1c4f891cd90637cea986d61a136 100644 (file)
@@ -385,7 +385,7 @@ int main (int argc, char **argv)
             VERBOSE (simul, TRACE, PRINTF ("no morep found '%s'\n", line));
             continue;
         }
-        VERBOSE (simul, DEBUG, PRINTF ("work with %c[%s]\n", comm->mode ? 'T' : 'R', serv->name));
+        VERBOSE (simul, DEBUG, PRINTF ("service %c:%s\n", comm->mode ? 'T' : 'R', serv->name));
 
         /* skip space */
         tmp = line + offset;
@@ -423,6 +423,12 @@ int main (int argc, char **argv)
                     msg = m;
                 }
             }
+            /* avoid null pointer */
+            if (msg == NULL) {
+                VERBOSE (simul, WARNING, PRINTF ("can't find msgtype %d for service %s\n", msgtype, serv->name));
+                continue;
+            }
+
         }
 
         /* check message and service */
@@ -430,7 +436,7 @@ int main (int argc, char **argv)
             VERBOSE (simul, WARNING, PRINTF ("message %s is not allowed for service %s (line '%s')\n", msg->name, serv->name, line));
             continue;
         }
-        VERBOSE (simul, DEBUG, PRINTF ("work with message %s\n", msg->name));
+        VERBOSE (simul, DEBUG, PRINTF ("message %s\n", msg->name));
 
         CHANNEL_t pdu_channel = {0};
         CLEAR_DATA_t pdu_clear_data = {0};
@@ -525,7 +531,7 @@ int main (int argc, char **argv)
             }
             /* check msg type */
             if (msg == NULL) {
-                VERBOSE (simul, WARNING, PRINTF ("R:%s[%s] [SEQ=%d MSG=%d LEN=%d PDU=%d] message type is not allowed for this service\n", serv->name, comm->etype, seqnum, msg->msgtype, len, pdu));
+                VERBOSE (simul, WARNING, PRINTF ("R:%s[%s] [SEQ=%d MSG=%d LEN=%d PDU=%d] message type is not allowed for this service\n", serv->name, comm->etype, seqnum, msgtype, len, pdu));
                 continue;
             }
             if (exp_msg->msgtype != msg->msgtype) {