From: nethack.rankin Date: Sat, 10 Mar 2012 02:49:08 +0000 (+0000) Subject: more dupstr (trunk only) X-Git-Tag: MOVE2GIT~46 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3c59c9e84b9a0c8866b476d7c62dd0cd6a9bc4f;p=nethack more dupstr (trunk only) --- diff --git a/src/files.c b/src/files.c index 36631d818..c899f259e 100644 --- a/src/files.c +++ b/src/files.c @@ -2363,7 +2363,7 @@ int src; #endif #ifdef USER_SOUNDS } else if (match_varname(buf, "SOUNDDIR", 8)) { - sounddir = (char *)dupstr(bufp); + sounddir = dupstr(bufp); } else if (match_varname(buf, "SOUND", 5)) { add_sound_mapping(bufp); #endif @@ -2372,15 +2372,15 @@ int src; } else if (match_varname(buf, "QT_TILEWIDTH", 12)) { extern char *qt_tilewidth; if (qt_tilewidth == NULL) - qt_tilewidth=(char *)dupstr(bufp); + qt_tilewidth = dupstr(bufp); } else if (match_varname(buf, "QT_TILEHEIGHT", 13)) { extern char *qt_tileheight; if (qt_tileheight == NULL) - qt_tileheight=(char *)dupstr(bufp); + qt_tileheight = dupstr(bufp); } else if (match_varname(buf, "QT_FONTSIZE", 11)) { extern char *qt_fontsize; if (qt_fontsize == NULL) - qt_fontsize=(char *)dupstr(bufp); + qt_fontsize = dupstr(bufp); } else if (match_varname(buf, "QT_COMPACT", 10)) { extern int qt_compact_mode; qt_compact_mode = atoi(bufp); diff --git a/src/mkobj.c b/src/mkobj.c index ef35d4869..01a67f8f7 100644 --- a/src/mkobj.c +++ b/src/mkobj.c @@ -172,12 +172,9 @@ new_omailcmd(otmp, response_cmd) struct obj *otmp; const char *response_cmd; { - unsigned lth = strlen(response_cmd) + 1; - if (!otmp->oextra) otmp->oextra = newoextra(); if (OMAILCMD(otmp)) free_omailcmd(otmp); - OMAILCMD(otmp) = (char *)alloc(lth); - Strcpy(OMAILCMD(otmp), response_cmd); + OMAILCMD(otmp) = dupstr(response_cmd); } void diff --git a/src/mon.c b/src/mon.c index 43b143a84..aff3ee4e2 100644 --- a/src/mon.c +++ b/src/mon.c @@ -1383,11 +1383,8 @@ struct monst *mtmp2, *mtmp1; if (!mtmp2->mextra) mtmp2->mextra = newmextra(); if (MNAME(mtmp1)) { - int lth = strlen(MNAME(mtmp1)) + 1; - if (lth) { - new_mname(mtmp2, lth); - Strcpy(MNAME(mtmp2), MNAME(mtmp1)); - } + new_mname(mtmp2, (int)strlen(MNAME(mtmp1)) + 1); + Strcpy(MNAME(mtmp2), MNAME(mtmp1)); } if (EGD(mtmp1)) { if (!EGD(mtmp2)) newegd(mtmp2); diff --git a/src/region.c b/src/region.c index e89822141..c3432291d 100644 --- a/src/region.c +++ b/src/region.c @@ -796,14 +796,10 @@ const char *msg_leave; NhRect tmprect; NhRegion *reg = create_region((NhRect *) 0, 0); - if (msg_enter) { - reg->enter_msg = (const char *) alloc(strlen(msg_enter) + 1); - Strcpy(reg->enter_msg, msg_enter); - } - if (msg_leave) { - reg->leave_msg = (const char *) alloc(strlen(msg_leave) + 1); - Strcpy(reg->leave_msg, msg_leave); - } + if (msg_enter) + reg->enter_msg = dupstr(msg_enter); + if (msg_leave) + reg->leave_msg = dupstr(msg_leave); tmprect.lx = x; tmprect.ly = y; tmprect.hx = x + w; diff --git a/src/rip.c b/src/rip.c index 1e39b2377..85d0c4016 100644 --- a/src/rip.c +++ b/src/rip.c @@ -96,10 +96,8 @@ time_t when; int line; rip = dp = (char **) alloc(sizeof(rip_txt)); - for (x = 0; rip_txt[x]; x++) { - dp[x] = (char *) alloc((unsigned int)(strlen(rip_txt[x]) + 1)); - Strcpy(dp[x], rip_txt[x]); - } + for (x = 0; rip_txt[x]; ++x) + dp[x] = dupstr(rip_txt[x]); dp[x] = (char *)0; /* Put name on stone */ diff --git a/src/sounds.c b/src/sounds.c index e7d78b16a..eaac43337 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -1098,8 +1098,7 @@ const char *mapping; new_map->regex.allocated = 0; new_map->regex.regs_allocated = REGS_FIXED; #else - new_map->pattern = (char *)alloc(strlen(text) + 1); - Strcpy(new_map->pattern, text); + new_map->pattern = dupstr(text); #endif new_map->filename = dupstr(filespec); new_map->volume = volume;