http://bugs.freeciv.org/Ticket/Display.html?id=39964 >
This is old and crufty code! Used malloc() instead of calloc(), so
uninitialized variables have bad data.
Server sent 0 for bool max (bad), and other fields (probably OK).
The client never set the default values (leaving them uninitialized),
although they were sent over the network.
And, client assert() for negative id, but never tested for id out of range.
And, client assert() for bad type.
And, client never tested for missing categories.
And, client never set various string pointers to NULL, so free() potentially
could have problems
Fixed all the above, adding LOG_ERROR instead of dying.
Never trust network data!
Also, use the same variable names in client, network, and server.
Compiles and runs for both GTK2 and XAW.
gui-win32 doesn't use proper symbols, so somebody else should fix it.
Index: server/settings.h
===
--- server/settings.h (revision 14152)
+++ server/settings.h (working copy)
@@ -71,9 +71,9 @@
* etc, and should end with a "."
*/
const char *extra_help;
- enum sset_type type;
- enum sset_category category;
- enum sset_level level;
+ enum sset_type stype;
+ enum sset_category scategory;
+ enum sset_level slevel;
/*
* About the *_validate functions: If the function is non-NULL, it
Index: server/stdinhand.c
===
--- server/stdinhand.c (revision 14152)
+++ server/stdinhand.c (working copy)
@@ -1114,7 +1114,7 @@
for (i=0;settings[i].name;i++) {
struct settings_s *op = &settings[i];
- switch (op->type) {
+ switch (op->stype) {
case SSET_INT:
fprintf(script_file, "set %s %i\n", op->name, *op->int_value);
break;
@@ -1551,7 +1551,7 @@
? _("changeable") : _("fixed")));
if (may_view_option(caller, id)) {
-switch (op->type) {
+switch (op->stype) {
case SSET_BOOL:
cmd_reply(help_cmd, caller, C_COMMENT,
_("Value: %d, Minimum: 0, Default: %d, Maximum: 1"),
@@ -1678,19 +1678,21 @@
sz_strlcpy(packet.short_help, setting->short_help);
sz_strlcpy(packet.extra_help, setting->extra_help);
-packet.category = setting->category;
-packet.type = setting->type;
-packet.class = setting->sclass;
+packet.stype = setting->stype;
+packet.scategory = setting->scategory;
+packet.sclass = setting->sclass;
packet.is_visible = (sset_is_to_client(setting_id)
|| pconn->access_level == ALLOW_HACK);
if (packet.is_visible) {
- switch (setting->type) {
+ switch (setting->stype) {
case SSET_STRING:
strcpy(packet.strval, setting->string_value);
strcpy(packet.default_strval, setting->string_default_value);
break;
case SSET_BOOL:
+ packet.min = FALSE;
+ packet.max = TRUE;
packet.val = *(setting->bool_value);
packet.default_val = setting->bool_default_value;
break;
@@ -1968,9 +1970,9 @@
int len = 0;
- if ((level == SSET_ALL || op->level == level || cmd >= 0
+ if ((level == SSET_ALL || op->slevel == level || cmd >= 0
|| level == SSET_CHANGED)) {
- switch (op->type) {
+ switch (op->stype) {
case SSET_BOOL:
if (*op->bool_value != op->bool_default_value) {
is_changed = TRUE;
@@ -2485,7 +2487,7 @@
do_update = FALSE;
buffer[0] = '\0';
- switch (op->type) {
+ switch (op->stype) {
case SSET_BOOL:
if (sscanf(arg, "%d", &val) != 1) {
cmd_reply(CMD_SET, caller, C_SYNTAX, _("Value must be an integer."));
Index: common/packets.def
===
--- common/packets.def (revision 14152)
+++ common/packets.def (working copy)
@@ -1327,8 +1327,8 @@
STRING short_help[MAX_LEN_PACKET];
STRING extra_help[MAX_LEN_PACKET];
- SSET_TYPE type;
- SSET_CLASS class;
+ SSET_TYPE stype;
+ SSET_CLASS sclass;
BOOL is_visible;
SINT32 val; /* value for bool or int */
@@ -1339,7 +1339,7 @@
STRING strval[MAX_LEN_PACKET]; /* space for string */
STRING default_strval[MAX_LEN_PACKET]; /* space for string */
- UINT8 category; /* which category this is in */
+ UINT8 scategory;
end
/** Effects hash packets **/
Index: manual/civmanual.c
===
--- manual/civmanual.c (revision 14152)
+++ manual/civmanual.c (working copy)
@@ -141,9 +141,9 @@
fprintf(doc, "%s\n\n", abuf.str);
}
fprintf(doc, "");
-fprintf(doc, _("Level: %s."), _(sset_level_names[op->level]));
+fprintf(doc, _("Level: %s."), _(sset_level_names[op->slevel]));
fprintf(doc, _("Category: %s."),
-_(sset_categ