[Freeciv-Dev] Re: (PR#11665) Technology Bug
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11665 >
Vasco Alexandre da Silva Costa wrote:
> Well, I can. get_tech_name() returns a *static* buffer. You run it three
> times, then the concatenation of the same static buffer is done 3x.
Well that's rather foolish. This patch should fix it but I haven't
tested it for future techs (which is really all that needs testing).
-jason
? gmon.out
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.80
diff -u -r1.80 tech.c
--- common/tech.c 19 Dec 2004 16:47:09 -0000 1.80
+++ common/tech.c 23 Dec 2004 18:46:50 -0000
@@ -570,37 +570,50 @@
return tech == A_FUTURE;
}
+#define SPECVEC_TAG string
+#define SPECVEC_TYPE char *
+#include "specvec.h"
+
/**************************************************************************
Return the name of the given tech. You don't have to free the return
pointer.
**************************************************************************/
const char *get_tech_name(const struct player *pplayer, Tech_Type_id tech)
{
- static char buffer[200];
+ static struct string_vector future;
+ int i;
+ /* We don't return a static buffer because that would break anything that
+ * needed to work with more than one name at a time. */
switch (tech) {
case A_NOINFO:
- my_snprintf(buffer, sizeof(buffer), _("(Unknown)"));
- break;
+ /* TRANS: "Unknown" tech */
+ return _("(Unknown)");
case A_UNSET:
- my_snprintf(buffer, sizeof(buffer), _("None"));
- break;
+ /* TRANS: "None" tech */
+ return _("None");
case A_FUTURE:
- my_snprintf(buffer, sizeof(buffer), _("Future Tech. %d"),
- pplayer->future_tech + 1);
- break;
+ for (i = future.size; i < pplayer->future_tech; i++) {
+ string_vector_append(&future, NULL);
+ }
+ if (!future.p[pplayer->future_tech - 1]) {
+ char buffer[1024];
+
+ my_snprintf(buffer, sizeof(buffer), _("Future Tech. %d"),
+ pplayer->future_tech + 1);
+ future.p[pplayer->future_tech - 1] = mystrdup(buffer);
+ }
+ return future.p[pplayer->future_tech - 1];
default:
/* Includes A_NONE */
if (!tech_exists(tech)) {
assert(0);
- my_snprintf(buffer, sizeof(buffer), _("(Unknown)"));
+ /* TRANS: "Unknown" tech */
+ return _("(Unknown)");
} else {
- my_snprintf(buffer, sizeof(buffer), "%s", advances[tech].name);
+ return advances[tech].name;
}
- break;
}
-
- return buffer;
}
/**************************************************************************
|
|