]> granicus.if.org Git - nethack/commitdiff
move null-check on tin_details()
authorSHIRAKATA Kentaro <argrath@ub32.org>
Tue, 8 Feb 2022 20:27:21 +0000 (05:27 +0900)
committerSHIRAKATA Kentaro <argrath@ub32.org>
Wed, 9 Feb 2022 20:16:29 +0000 (05:16 +0900)
Move null-check of obj and buf before their first use.

src/eat.c

index ce264a2ab0f043964fde58e49df237bade28d767..b2fc857e4ad86118adab81284187345201241dc8 100644 (file)
--- a/src/eat.c
+++ b/src/eat.c
@@ -1237,30 +1237,32 @@ void
 tin_details(struct obj *obj, int mnum, char *buf)
 {
     char buf2[BUFSZ];
+
+    if (!obj || !buf)
+        return;
+
     int r = tin_variety(obj, TRUE);
 
-    if (obj && buf) {
-        if (r == SPINACH_TIN)
-            Strcat(buf, " of spinach");
-        else if (mnum == NON_PM)
-            Strcpy(buf, "empty tin");
-        else {
-            if ((obj->cknown || iflags.override_ID) && obj->spe < 0) {
-                if (r == ROTTEN_TIN || r == HOMEMADE_TIN) {
-                    /* put these before the word tin */
-                    Sprintf(buf2, "%s %s of ", tintxts[r].txt, buf);
-                    Strcpy(buf, buf2);
-                } else {
-                    Sprintf(eos(buf), " of %s ", tintxts[r].txt);
-                }
+    if (r == SPINACH_TIN)
+        Strcat(buf, " of spinach");
+    else if (mnum == NON_PM)
+        Strcpy(buf, "empty tin");
+    else {
+        if ((obj->cknown || iflags.override_ID) && obj->spe < 0) {
+            if (r == ROTTEN_TIN || r == HOMEMADE_TIN) {
+                /* put these before the word tin */
+                Sprintf(buf2, "%s %s of ", tintxts[r].txt, buf);
+                Strcpy(buf, buf2);
             } else {
-                Strcpy(eos(buf), " of ");
+                Sprintf(eos(buf), " of %s ", tintxts[r].txt);
             }
-            if (vegetarian(&mons[mnum]))
-                Sprintf(eos(buf), "%s", mons[mnum].pmnames[NEUTRAL]);
-            else
-                Sprintf(eos(buf), "%s meat", mons[mnum].pmnames[NEUTRAL]);
+        } else {
+            Strcpy(eos(buf), " of ");
         }
+        if (vegetarian(&mons[mnum]))
+            Sprintf(eos(buf), "%s", mons[mnum].pmnames[NEUTRAL]);
+        else
+            Sprintf(eos(buf), "%s meat", mons[mnum].pmnames[NEUTRAL]);
     }
 }