Author: sveinung
Date: Sun Aug 16 10:37:43 2015
New Revision: 29542

URL: http://svn.gna.org/viewcvs/freeciv?rev=29542&view=rev
Log:
Consistent get action structure error handling

See patch #6236

Modified:
    trunk/common/actions.c

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=29542&r1=29541&r2=29542&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Sun Aug 16 10:37:43 2015
@@ -217,9 +217,19 @@
 
 /**************************************************************************
   Return the action with the given id.
+
+  Returns NULL if no action with the given id exists.
 **************************************************************************/
 struct action *action_by_number(int action_id)
 {
+  if (!action_id_is_valid(action_id)) {
+    /* Nothing to return. */
+
+    log_verbose("Asked for non existing action numbered %d", action_id);
+
+    return NULL;
+  }
+
   fc_assert_msg(actions[action_id], "Action %d don't exist.", action_id);
 
   return actions[action_id];
@@ -227,6 +237,8 @@
 
 /**************************************************************************
   Return the action with the given name.
+
+  Returns NULL if no action with the given name exists.
 **************************************************************************/
 struct action *action_by_rule_name(const char *name)
 {
@@ -234,6 +246,10 @@
   int action_id = gen_action_by_name(name, fc_strcasecmp);
 
   if (!action_id_is_valid(action_id)) {
+    /* Nothing to return. */
+
+    log_verbose("Asked for non existing action named %s", name);
+
     return NULL;
   }
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to