]> granicus.if.org Git - nethack/commitdiff
Fix gcc sprintf warnings
authorDean Luick <dean@nethack.org>
Sat, 9 Jan 2021 02:33:39 +0000 (20:33 -0600)
committerDean Luick <dean@nethack.org>
Sun, 17 Jan 2021 01:44:56 +0000 (19:44 -0600)
Gcc 9 has become more vocal with sprintf buffer overflow
checking.  Remove these sprintf warnings by changing the
offending calls to a snprintf wrapper that will explicitly
check the result.

17 files changed:
src/botl.c
src/cmd.c
src/do_name.c
src/do_wear.c
src/dungeon.c
src/eat.c
src/insight.c
src/mhitm.c
src/options.c
src/pager.c
src/potion.c
src/spell.c
src/topten.c
src/trap.c
src/uhitm.c
win/curses/cursinit.c
win/tty/wintty.c

index b99de1ed0920ed2a33b43468c2eea5d13642b93f..413f912cec9e2b8e0cc031a5dcf0f2ca5e1ec7ff 100644 (file)
@@ -216,17 +216,21 @@ do_statusline2()
      * interface supports that.
      */
     if ((dln - dx) + 1 + hln + 1 + xln + 1 + tln + 1 + cln <= COLNO) {
-        Sprintf(newbot2, "%s %s %s %s %s", dloc, hlth, expr, tmmv, cond);
+        Snprintf(newbot2, sizeof(newbot2), "%s %s %s %s %s", dloc, hlth, expr,
+                 tmmv, cond);
     } else {
         if (dln + 1 + hln + 1 + xln + 1 + tln + 1 + cln + 1 > MAXCO) {
             panic("bot2: second status line exceeds MAXCO (%u > %d)",
                   (dln + 1 + hln + 1 + xln + 1 + tln + 1 + cln + 1), MAXCO);
         } else if ((dln - dx) + 1 + hln + 1 + xln + 1 + cln <= COLNO) {
-            Sprintf(newbot2, "%s %s %s %s %s", dloc, hlth, expr, cond, tmmv);
+            Snprintf(newbot2, sizeof(newbot2), "%s %s %s %s %s", dloc, hlth,
+                     expr, cond, tmmv);
         } else if ((dln - dx) + 1 + hln + 1 + cln <= COLNO) {
-            Sprintf(newbot2, "%s %s %s %s %s", dloc, hlth, cond, expr, tmmv);
+            Snprintf(newbot2, sizeof(newbot2), "%s %s %s %s %s", dloc, hlth,
+                     cond, expr, tmmv);
         } else {
-            Sprintf(newbot2, "%s %s %s %s %s", hlth, cond, dloc, expr, tmmv);
+            Snprintf(newbot2, sizeof(newbot2), "%s %s %s %s %s", hlth, cond,
+                     dloc, expr, tmmv);
         }
         /* only two or three consecutive spaces available to squeeze out */
         mungspaces(newbot2);
@@ -3134,8 +3138,8 @@ status_hilite_linestr_gather_conditions()
                 tmpattr = hlattr2attrname(atr, attrbuf, BUFSZ);
                 if (tmpattr)
                     Sprintf(eos(clrbuf), "&%s", tmpattr);
-                Sprintf(condbuf, "condition/%s/%s",
-                        conditionbitmask2str(cond_maps[i].bm), clrbuf);
+                Snprintf(condbuf, sizeof(condbuf), "condition/%s/%s",
+                         conditionbitmask2str(cond_maps[i].bm), clrbuf);
                 status_hilite_linestr_add(BL_CONDITION, 0,
                                           cond_maps[i].bm, condbuf);
             }
@@ -3236,7 +3240,8 @@ struct hilite_s *hl;
         if ((tmpattr = hlattr2attrname(attr, attrbuf, BUFSZ)) != 0)
             Sprintf(eos(clrbuf), "&%s", tmpattr);
     }
-    Sprintf(buf, "%s/%s/%s", initblstats[hl->fld].fldname, behavebuf, clrbuf);
+    Snprintf(buf, sizeof(buf), "%s/%s/%s", initblstats[hl->fld].fldname,
+             behavebuf, clrbuf);
 
     return buf;
 }
index 1c7f466ed6c4aaf60462060807be55828531d113..bfc9ece1c691de91cdd36d3d3fbc358a3004a10e 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -674,7 +674,7 @@ extcmd_via_menu()
             add_menu(win, &nul_glyphinfo, &any, any.a_char, 0,
                      ATR_NONE, buf, MENU_ITEMFLAGS_NONE);
         }
-        Sprintf(prompt, "Extended Command: %s", cbuf);
+        Snprintf(prompt, sizeof(prompt), "Extended Command: %s", cbuf);
         end_menu(win, prompt);
         n = select_menu(win, PICK_ONE, &pick_list);
         destroy_nhwindow(win);
@@ -2392,7 +2392,8 @@ dokeylist(VOID_ARGS)
                 Sprintf(buf2, "[%s]", spkey_name(j));
                 /* lines up with the other unassigned commands which use
                    "#%-20s ", but not with the other special keys */
-                Sprintf(buf, "%-21s %s", buf2, misc_keys[i].desc);
+                Snprintf(buf, sizeof(buf), "%-21s %s", buf2,
+                         misc_keys[i].desc);
                 putstr(datawin, 0, buf);
             }
         }
@@ -4807,7 +4808,8 @@ const char *prompt;
                 Strcpy(pbuf + (QBUFSZ - 1) - k - 4, "...?"); /* -4: "...?" */
             }
 
-            Sprintf(qbuf, "%s%s %s", promptprefix, pbuf, responsetype);
+            Snprintf(qbuf, sizeof(qbuf), "%s%s %s", promptprefix, pbuf,
+                     responsetype);
             *ans = '\0';
             getlin(qbuf, ans);
             (void) mungspaces(ans);
index f0374b931dcbc4afa84c41386589f288338df49b..d74818069608c99a79ba7227df1730c041e96183 100644 (file)
@@ -205,7 +205,8 @@ const char *goal;
         } else {
             Sprintf(kbuf, "'%s'", visctrl(g.Cmd.spkeys[NHKF_GETPOS_PICK]));
         }
-        Sprintf(sbuf, "Type a %s when you are at the right place.", kbuf);
+        Snprintf(sbuf, sizeof(sbuf),
+                 "Type a %s when you are at the right place.", kbuf);
         putstr(tmpwin, 0, sbuf);
         if (doing_what_is) {
             Sprintf(sbuf,
index ebdf6102ce9992f5df3d3a4c745945a59f0dcd8b..c8b84e1fea6421e964593928252f2e59f6d32d80 100644 (file)
@@ -1514,7 +1514,8 @@ struct obj *obj;
                     Strcat(what, " and ");
                 Strcat(what, suit_simple_name(uarm));
             }
-            Sprintf(why, " without taking off your %s first", what);
+            Snprintf(why, sizeof(why), " without taking off your %s first",
+                     what);
         } else {
             Strcpy(why, "; it's embedded");
         }
index 907bf2765e6aa3a28fb0d5a4ece22567cf6be188..7e6da324425fd0955289f3ddb6baf11ee69c700f 100644 (file)
@@ -3537,8 +3537,8 @@ boolean printdun;
                 (void) strsubst(tmpbuf, " herself", " yourself");
                 (void) strsubst(tmpbuf, " his ", " your ");
                 (void) strsubst(tmpbuf, " her ", " your ");
-                Sprintf(buf, "%s%syou, %s%c", PREFIX, TAB, tmpbuf,
-                        --kncnt ? ',' : '.');
+                Snprintf(buf, sizeof(buf), "%s%syou, %s%c", PREFIX, TAB,
+                         tmpbuf, --kncnt ? ',' : '.');
                 putstr(win, 0, buf);
             }
             for (bp = mptr->final_resting_place; bp; bp = bp->next) {
index 72254a9934aacee31319dbc5fdf3ae4a11f388f7..77b7b1c6cb02d2e1cfd9225c8252cf94442550b1 100644 (file)
--- a/src/eat.c
+++ b/src/eat.c
@@ -2353,16 +2353,17 @@ struct obj *otmp;
      */
     if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && !Sick_resistance) {
         /* Tainted meat */
-        Sprintf(buf, "%s like %s could be tainted!  %s", foodsmell, it_or_they,
-                eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s like %s could be tainted!  %s",
+                 foodsmell, it_or_they, eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
             return 2;
     }
     if (stoneorslime) {
-        Sprintf(buf, "%s like %s could be something very dangerous!  %s",
-                foodsmell, it_or_they, eat_it_anyway);
+        Snprintf(buf, sizeof(buf),
+                 "%s like %s could be something very dangerous!  %s",
+                 foodsmell, it_or_they, eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
@@ -2370,8 +2371,8 @@ struct obj *otmp;
     }
     if (otmp->orotten || (cadaver && rotted > 3L)) {
         /* Rotten */
-        Sprintf(buf, "%s like %s could be rotten! %s",  foodsmell, it_or_they,
-                eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s like %s could be rotten! %s",
+                 foodsmell, it_or_they, eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
@@ -2379,8 +2380,8 @@ struct obj *otmp;
     }
     if (cadaver && poisonous(&mons[mnum]) && !Poison_resistance) {
         /* poisonous */
-        Sprintf(buf, "%s like %s might be poisonous!  %s", foodsmell,
-                it_or_they, eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s like %s might be poisonous!  %s",
+                 foodsmell, it_or_they, eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
@@ -2388,20 +2389,22 @@ struct obj *otmp;
     }
     if (otmp->otyp == APPLE && otmp->cursed && !Sleep_resistance) {
         /* causes sleep, for long enough to be dangerous */
-        Sprintf(buf, "%s like %s might have been poisoned.  %s", foodsmell,
-                it_or_they, eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s like %s might have been poisoned.  %s",
+                 foodsmell, it_or_they, eat_it_anyway);
         return (yn_function(buf, ynchars, 'n') == 'n') ? 1 : 2;
     }
     if (cadaver && !vegetarian(&mons[mnum]) && !u.uconduct.unvegetarian
         && Role_if(PM_MONK)) {
-        Sprintf(buf, "%s unhealthy.  %s", foodsmell, eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s unhealthy.  %s", foodsmell,
+                 eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
             return 2;
     }
     if (cadaver && acidic(&mons[mnum]) && !Acid_resistance) {
-        Sprintf(buf, "%s rather acidic.  %s", foodsmell, eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s rather acidic.  %s",
+                 foodsmell, eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
@@ -2409,8 +2412,8 @@ struct obj *otmp;
     }
     if (Upolyd && u.umonnum == PM_RUST_MONSTER && is_metallic(otmp)
         && otmp->oerodeproof) {
-        Sprintf(buf, "%s disgusting to you right now.  %s", foodsmell,
-                eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s disgusting to you right now.  %s",
+                 foodsmell, eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
@@ -2424,8 +2427,8 @@ struct obj *otmp;
         && ((material == LEATHER || material == BONE
              || material == DRAGON_HIDE || material == WAX)
             || (cadaver && !vegan(&mons[mnum])))) {
-        Sprintf(buf, "%s foul and unfamiliar to you.  %s", foodsmell,
-                eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s foul and unfamiliar to you.  %s",
+                 foodsmell, eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
@@ -2435,7 +2438,8 @@ struct obj *otmp;
         && ((material == LEATHER || material == BONE
              || material == DRAGON_HIDE)
             || (cadaver && !vegetarian(&mons[mnum])))) {
-        Sprintf(buf, "%s unfamiliar to you.  %s", foodsmell, eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s unfamiliar to you.  %s",
+                 foodsmell, eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
@@ -2444,8 +2448,8 @@ struct obj *otmp;
 
     if (cadaver && mnum != PM_ACID_BLOB && rotted > 5L && Sick_resistance) {
         /* Tainted meat with Sick_resistance */
-        Sprintf(buf, "%s like %s could be tainted!  %s",
-                foodsmell, it_or_they, eat_it_anyway);
+        Snprintf(buf, sizeof(buf), "%s like %s could be tainted!  %s",
+                 foodsmell, it_or_they, eat_it_anyway);
         if (yn_function(buf, ynchars, 'n') == 'n')
             return 1;
         else
index eaf0f5aa23f1523c961c2363a45bef4f514e68aa..a5cb1ecb62324e20ed592ce67b0e5a2ba63e476f 100644 (file)
@@ -242,8 +242,8 @@ int final; /* ENL_GAMEINPROGRESS:0, ENL_GAMEOVERALIVE, ENL_GAMEOVERDEAD */
     *tmpbuf = highc(*tmpbuf); /* same adjustment as bottom line */
     /* as in background_enlightenment, when poly'd we need to use the saved
        gender in u.mfemale rather than the current you-as-monster gender */
-    Sprintf(buf, "%s the %s's attributes:", tmpbuf,
-            ((Upolyd ? u.mfemale : flags.female) && g.urole.name.f)
+    Snprintf(buf, sizeof(buf), "%s the %s's attributes:", tmpbuf,
+             ((Upolyd ? u.mfemale : flags.female) && g.urole.name.f)
                 ? g.urole.name.f
                 : g.urole.name.m);
 
@@ -330,9 +330,10 @@ int final;
             Sprintf(eos(tmpbuf), "%s in ",
                     pmname(&mons[g.youmonst.cham],
                            flags.female ? FEMALE : MALE));
-        Sprintf(buf, "%s%s%s%s form", !final ? "currently " : "",
-                altphrasing ? just_an(anbuf, tmpbuf) : "in ",
-                tmpbuf, pmname(uasmon, flags.female ? FEMALE : MALE));
+        Snprintf(buf, sizeof(buf), "%s%s%s%s form",
+                 !final ? "currently " : "",
+                 altphrasing ? just_an(anbuf, tmpbuf) : "in ",
+                 tmpbuf, pmname(uasmon, flags.female ? FEMALE : MALE));
         you_are(buf, "");
     }
 
@@ -427,8 +428,8 @@ int final;
         int egdepth = observable_depth(&u.uz);
 
         (void) endgamelevelname(tmpbuf, egdepth);
-        Sprintf(buf, "in the endgame, on the %s%s",
-                !strncmp(tmpbuf, "Plane", 5) ? "Elemental " : "", tmpbuf);
+        Snprintf(buf, sizeof(buf), "in the endgame, on the %s%s",
+                 !strncmp(tmpbuf, "Plane", 5) ? "Elemental " : "", tmpbuf);
     } else if (Is_knox(&u.uz)) {
         /* this gives away the fact that the knox branch is only 1 level */
         Sprintf(buf, "on the %s level", g.dungeons[u.uz.dnum].dname);
@@ -448,7 +449,7 @@ int final;
             Strcat(tmpbuf, ", a primitive area");
         else if (Is_bigroom(&u.uz) && !Blind)
             Strcat(tmpbuf, ", a very big room");
-        Sprintf(buf, "in %s, on %s", dgnbuf, tmpbuf);
+        Snprintf(buf, sizeof(buf), "in %s, on %s", dgnbuf, tmpbuf);
     }
     you_are(buf, "");
 
@@ -1216,7 +1217,7 @@ int final;
                     Strcat(buf, " and two weapons");
                     if (also3) {
                         Strcpy(pfx, "You also ");
-                        Sprintf(sfx, " %s", buf), buf[0] = '\0';
+                        Snprintf(sfx, sizeof(sfx), " %s", buf), buf[0] = '\0';
                         verb_present = hav2 ? "have" : "are";
                         verb_past = hav2 ? "had" : "were";
                     }
@@ -2479,7 +2480,7 @@ boolean ask;
                           : !digit(buf[2]) ? 4 : 0;
                 if (class_header)
                     ++pfx;
-                Sprintf(buftoo, "%*s%s", pfx, "", buf);
+                Snprintf(buftoo, sizeof(buftoo), "%*s%s", pfx, "", buf);
                 putstr(klwin, 0, buftoo);
             }
             /*
index f868430358c4aece7c3ddbd09e331b1883667346..797b3ee3295c6a151cd8a00390307632813d784e 100644 (file)
@@ -576,29 +576,29 @@ int dieroll;
             buf[0] = '\0';
             switch (mattk->aatyp) {
             case AT_BITE:
-                Sprintf(buf, "%s bites", magr_name);
+                Snprintf(buf, sizeof(buf), "%s bites", magr_name);
                 break;
             case AT_STNG:
-                Sprintf(buf, "%s stings", magr_name);
+                Snprintf(buf, sizeof(buf), "%s stings", magr_name);
                 break;
             case AT_BUTT:
-                Sprintf(buf, "%s butts", magr_name);
+                Snprintf(buf, sizeof(buf), "%s butts", magr_name);
                 break;
             case AT_TUCH:
-                Sprintf(buf, "%s touches", magr_name);
+                Snprintf(buf, sizeof(buf), "%s touches", magr_name);
                 break;
             case AT_TENT:
-                Sprintf(buf, "%s tentacles suck", s_suffix(magr_name));
+                Snprintf(buf, sizeof(buf), "%s tentacles suck", s_suffix(magr_name));
                 break;
             case AT_HUGS:
                 if (magr != u.ustuck) {
-                    Sprintf(buf, "%s squeezes", magr_name);
+                    Snprintf(buf, sizeof(buf), "%s squeezes", magr_name);
                     break;
                 }
                 /*FALLTHRU*/
             default:
                 if (!weaponhit || !mwep || !mwep->oartifact)
-                    Sprintf(buf, "%s hits", magr_name);
+                    Snprintf(buf, sizeof(buf), "%s hits", magr_name);
                 break;
             }
             if (*buf)
index eec4d7e328b72a941fbbbedc227e7fe9b55c8d3d..e8dd2412a3d3517d9515063e132f3c2cf2a9577d 100644 (file)
@@ -8283,8 +8283,8 @@ option_help()
             || (is_wc2_option(optname) && !wc2_supported(optname)))
             continue;
         Sprintf(buf2, "`%s'", optname);
-        Sprintf(buf, "%-20s - %s%c", buf2, allopt[i].descr,
-                allopt[i + 1].name ? ',' : '.');
+        Snprintf(buf, sizeof(buf), "%-20s - %s%c", buf2, allopt[i].descr,
+                 allopt[i + 1].name ? ',' : '.');
         putstr(datawin, 0, buf);
     }
     putstr(datawin, 0, "");
index fb96e98b5bd6782e8b530a3e9e06111740ae7737..20346430ea261b336a6955b1f13215b51e5a4652 100644 (file)
@@ -1207,13 +1207,13 @@ struct permonst **for_supplement;
 
             *firstmatch = look_buf;
             if (*(*firstmatch)) {
-                Sprintf(temp_buf, " (%s)", *firstmatch);
+                Snprintf(temp_buf, sizeof(temp_buf), " (%s)", *firstmatch);
                 (void) strncat(out_str, temp_buf,
                                BUFSZ - strlen(out_str) - 1);
                 found = 1; /* we have something to look up */
             }
             if (monbuf[0]) {
-                Sprintf(temp_buf, " [seen: %s]", monbuf);
+                Snprintf(temp_buf, sizeof(temp_buf), " [seen: %s]", monbuf);
                 (void) strncat(out_str, temp_buf,
                                BUFSZ - strlen(out_str) - 1);
             }
index 0cdb38e325f0e43f118ff6e079d36179741a3407..7e339728c6433e95e458dd23353bcad826f532ce 100644 (file)
@@ -1425,7 +1425,8 @@ int how;
 
         switch (obj->otyp) {
         case POT_WATER:
-            Sprintf(saddle_glows, "%s %s", buf, aobjnam(saddle, "glow"));
+            Snprintf(saddle_glows, sizeof(saddle_glows), "%s %s",
+                     buf, aobjnam(saddle, "glow"));
             affected = H2Opotion_dip(obj, saddle, useeit, saddle_glows);
             break;
         case POT_POLYMORPH:
@@ -1975,8 +1976,8 @@ dodip()
     here = levl[u.ux][u.uy].typ;
     /* Is there a fountain to dip into here? */
     if (IS_FOUNTAIN(here)) {
-        Sprintf(qbuf, "%s%s into the fountain?", Dip_,
-                flags.verbose ? obuf : shortestname);
+        Snprintf(qbuf, sizeof(qbuf), "%s%s into the fountain?", Dip_,
+                 flags.verbose ? obuf : shortestname);
         /* "Dip <the object> into the fountain?" */
         if (yn(qbuf) == 'y') {
             dipfountain(obj);
@@ -1985,8 +1986,8 @@ dodip()
     } else if (is_pool(u.ux, u.uy)) {
         const char *pooltype = waterbody_name(u.ux, u.uy);
 
-        Sprintf(qbuf, "%s%s into the %s?", Dip_,
-                flags.verbose ? obuf : shortestname, pooltype);
+        Snprintf(qbuf, sizeof(qbuf), "%s%s into the %s?", Dip_,
+                 flags.verbose ? obuf : shortestname, pooltype);
         /* "Dip <the object> into the {pool, moat, &c}?" */
         if (yn(qbuf) == 'y') {
             if (Levitation) {
@@ -2005,7 +2006,8 @@ dodip()
     }
 
     /* "What do you want to dip <the object> into? [xyz or ?*] " */
-    Sprintf(qbuf, "dip %s into", flags.verbose ? obuf : shortestname);
+    Snprintf(qbuf, sizeof(qbuf), "dip %s into",
+             flags.verbose ? obuf : shortestname);
     potion = getobj(qbuf, drink_ok, GETOBJ_NOFLAGS);
     if (!potion)
         return 0;
index bea26783e6ea4127b59ea04c0aa9a660fade884e..776f05ec834f0e168a238276689915ae6b9fc4e7 100644 (file)
@@ -715,7 +715,8 @@ int *spell_no;
             Sprintf(lets, "a-zA-%c", 'A' + nspells - 27);
 
         for (;;) {
-            Sprintf(qbuf, "Cast which spell? [%s *?]", lets);
+            Snprintf(qbuf, sizeof(qbuf), "Cast which spell? [%s *?]",
+                     lets);
             ilet = yn_function(qbuf, (char *) 0, '\0');
             if (ilet == '*' || ilet == '?')
                 break; /* use menu mode */
index db9208114e334d41a8df8d7b5b6ce1a6ca4480af..5542780370397063a4ffcbee11f4974691db22ca 100644 (file)
@@ -1058,7 +1058,7 @@ boolean so;
             topten_print_bold(linebuf);
         } else
             topten_print(linebuf);
-        Sprintf(linebuf, "%15s %s", "", linebuf3);
+        Snprintf(linebuf, sizeof(linebuf), "%15s %s", "", linebuf3);
         lngr = strlen(linebuf);
     }
     /* beginning of hp column not including padding */
index 00d4140adb15bc5875d430189cc59c483b424bf8..6cfd0e61d4738faec99512f4e922b94096f94eb2 100644 (file)
@@ -4838,11 +4838,14 @@ boolean force;
                     trap_skipped = TRUE;
                     deal_with_floor_trap = FALSE;
                 } else {
-                    Sprintf(
-                        qbuf, "There %s and %s here.  %s %s?",
-                        (boxcnt == 1) ? "is a container" : "are containers",
-                        an(trapdescr),
-                        (ttmp->ttyp == WEB) ? "Remove" : "Disarm", the_trap);
+                    Snprintf(qbuf, sizeof(qbuf),
+                             "There %s and %s here.  %s %s?",
+                             (boxcnt == 1) ? "is a container"
+                                           : "are containers",
+                             an(trapdescr),
+                             (ttmp->ttyp == WEB) ? "Remove"
+                                                 : "Disarm",
+                             the_trap);
                     switch (ynq(qbuf)) {
                     case 'q':
                         return 0;
index 102db57e45bcb3728e8d4e5093ba785e9be46fba..09db7c85237c951c86b862cf4e21d96fcd3e8003 100644 (file)
@@ -1320,11 +1320,12 @@ int dieroll;
             else if (silverobj && saved_oname[0]) {
                 /* guard constructed format string against '%' in
                    saved_oname[] from xname(via cxname()) */
-                Sprintf(silverobjbuf, "Your %s%s %s",
-                        strstri(saved_oname, "silver") ? "" : "silver ",
-                        saved_oname, vtense(saved_oname, "sear"));
+                Snprintf(silverobjbuf, sizeof(silverobjbuf), "Your %s%s %s",
+                         strstri(saved_oname, "silver") ? "" : "silver ",
+                         saved_oname, vtense(saved_oname, "sear"));
                 (void) strNsubst(silverobjbuf, "%", "%%", 0);
-                Strcat(silverobjbuf, " %s!");
+                strncat(silverobjbuf, " %s!",
+                        sizeof(silverobjbuf) - (strlen(silverobjbuf) + 1));
                 fmt = silverobjbuf;
             } else
                 fmt = "The silver sears %s!";
index 27c6fc9cbe30606773f256f6bf5cd141a3a47b3c..5ab6af594eb17ae112a943b028c596a2e9effb03 100644 (file)
@@ -451,7 +451,7 @@ curses_choose_character()
     }
 
     prompt[count_off] = '\0';
-    sprintf(choice, "%s%c", tmpchoice, '\033');
+    Snprintf(choice, sizeof(choice), "%s%c", tmpchoice, '\033');
     if (strchr(tmpchoice, 't')) {       /* Tutorial mode */
         mvaddstr(0, 1, "New? Press t to enter a tutorial.");
     }
index a272118aed1c103a22b392a590a92153d79a1f15..12ef0c903981714826fd4c85385eabc59cc0d934 100644 (file)
@@ -961,10 +961,10 @@ tty_player_selection()
             Sprintf(plbuf, " %s", genders[GEND].adj);
         else
             *plbuf = '\0'; /* omit redundant gender */
-        Sprintf(pbuf, "%s, %s%s %s %s", g.plname, aligns[ALGN].adj, plbuf,
-                races[RACE].adj,
-                (GEND == 1 && roles[ROLE].name.f) ? roles[ROLE].name.f
-                                                  : roles[ROLE].name.m);
+        Snprintf(pbuf, sizeof(pbuf), "%s, %s%s %s %s", g.plname,
+                 aligns[ALGN].adj, plbuf, races[RACE].adj,
+                 (GEND == 1 && roles[ROLE].name.f) ? roles[ROLE].name.f
+                                                   : roles[ROLE].name.m);
         add_menu(win, &nul_glyphinfo, &any, 0, 0, ATR_NONE, pbuf,
                  MENU_ITEMFLAGS_NONE);
         /* blank separator */