Re: [Freeciv-Dev] (PR#40084) identity_number, server.game_identifier, city_tile(), unit_tile()
http://bugs.freeciv.org/Ticket/Display.html?id=40084 > Forgot to mention that it fixes the bug already reported in PR#40080, increasing the ai->stats.diplomat_reservations bit vector from 32767 (wrong) to 65536. Better not to overflow, even as a better solution may be developed in the future Committed trunk revision 14386. Committed S2_2 revision 14387. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#40084) identity_number, server.game_identifier, city_tile(), unit_tile()
http://bugs.freeciv.org/Ticket/Display.html?id=40084 > Some of the preliminary steps toward the PR#40080 long-term goal. This patch mostly clears the decks for shorter-term crashing bug fixes. It includes some code already in 2.1 (PR#39980), used for initializing the game_identifier. Moved from game to server structure (it is server-only), and renamed to help distinguish from other "id" Modified PR#40079, moving (and renaming) IDENTITY_NUMBER_ZERO to fc_types.h, instead of "0" initializing city and unit ids. Added access functions city_tile() and unit_tile(), renaming conflicting variable names. Index: utility/shared.c === --- utility/shared.c(revision 14385) +++ utility/shared.c(working copy) @@ -47,6 +47,7 @@ #include "fcintl.h" #include "log.h" #include "mem.h" +#include "rand.h" #include "support.h" #include "shared.h" @@ -79,6 +80,10 @@ static char *grouping = NULL; static char *grouping_sep = NULL; +static const char base64url[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; + + /*** Take a string containing multiple lines and create a copy where each line is padded to the length of the longest line and centered. @@ -390,22 +395,15 @@ / bool is_safe_filename(const char *name) { - int i; + int i = 0; /* must not be NULL or empty */ if (!name || *name == '\0') { return FALSE; } - /* Accept only alphanumerics and '-', '_', '.' The exception is if - * part of PARENT_DIR_OPERATOR is one of these, which is prohibited */ - for (i = 0; name[i]; i++) { -if (!((name[i] <= 'z' && name[i] >= 'a') - || (name[i] <= 'Z' && name[i] >= 'A') - || (name[i] <= '9' && name[i] >= '0') - || name[i] == '-' - || name[i] == '_' - || name[i] == '.')) { + for (; '\0' != name[i]; i++) { +if ('.' != name[i] && NULL == strchr(base64url, name[i])) { return FALSE; } } @@ -457,6 +455,45 @@ return TRUE; } +/* + Check for valid base64url. +*/ +bool is_base64url(const char *s) +{ + size_t i = 0; + + /* must not be NULL or empty */ + if (NULL == s || '\0' == *s) { +return FALSE; + } + + for (; '\0' != s[i]; i++) { +if (NULL == strchr(base64url, s[i])) { + return FALSE; +} + } + return TRUE; +} + +/* + generate a random string meeting criteria such as is_ascii_name(), + is_base64url(), and is_safe_filename(). +*/ +void randomize_base64url_string(char *s, size_t n) +{ + size_t i = 0; + + /* must not be NULL or too short */ + if (NULL == s || 1 > n) { +return; + } + + for (; i < (n - 1); i++) { +s[i] = base64url[myrand(sizeof(base64url) - 1)]; + } + s[i] = '\0'; +} + /*** Produce a statically allocated textual representation of the given year. Index: utility/shared.h === --- utility/shared.h(revision 14385) +++ utility/shared.h(working copy) @@ -25,8 +25,9 @@ #endif #endif +/* Changing these will break network compatability! */ #define MAX_LEN_ADDR 256 /* see also MAXHOSTNAMELEN and RFC 1123 2.1 */ -#define MAX_LEN_PATH 4095 +#define MAX_LEN_PATH4095 /* Use FC_INFINITY to denote that a certain event will never occur or another unreachable condition. */ @@ -144,8 +145,11 @@ const char *int_to_text(unsigned int number); bool is_ascii_name(const char *name); +bool is_base64url(const char *s); bool is_safe_filename(const char *name); +void randomize_base64url_string(char *s, size_t n); const char *textyear(int year); + int compare_strings(const void *first, const void *second); int compare_strings_ptrs(const void *first, const void *second); Index: server/score.c === --- server/score.c (revision 14385) +++ server/score.c (working copy) @@ -399,7 +399,7 @@ return; } - fprintf(fp, "P3\n# version:2\n# gameid: %s\n", game.id); + fprintf(fp, "P3\n# version:2\n# gameid: %s\n", server.game_identifier); fprintf(fp, "# An intermediate map from saved Freeciv game %s%+05d\n", game.save_name, game.info.year); Index: server/srv_main.c === --- server/srv_main.c (revision 14385) +++ server/srv_main.c (working copy) @@ -1096,7 +1096,7 @@ } /** - Truncation of un
Re: [Freeciv-Dev] (PR#40082) string coding error in script.lua
http://bugs.freeciv.org/Ticket/Display.html?id=40082 > The easy fix is just to shorten this to one line. This doesn't solve the problem that xgettext doesn't properly know how to extract translatable strings from lua code, nor from embedded lua code (as in the tutorial scenario). -jason ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#40075) S2_2 memory error in map_get_player_city
http://bugs.freeciv.org/Ticket/Display.html?id=40075 > On Feb 5, 2008 5:58 AM, William Allen Simpson <[EMAIL PROTECTED]> wrote: > > http://bugs.freeciv.org/Ticket/Display.html?id=40075 > > > Michael Kaufman wrote: > > On Mon, Feb 04, 2008 at 07:49:58PM -0800, Jason Dorje Short wrote: > >> ... Why not just use the ptile->index as the city id? ... > > > > ... > > without knowing the tile location that the city sits on (the capital city?) > > > I really like Jason's idea. It might take time to implement, but it could > ameliorate half a dozen recent bug reports that come to mind. And this > would be a good time to eliminate the id field, as 2.2 will never generate > savegames readable by earlier versions (because of new terrain). Much as I like this idea there are some significant hurdles. * punit->homecity will basically have to be changed to punit->hometile (or just punit->home, a tile pointer). This field must then not be shown to other players (which may be the case already). * pplayer->capital (?) must not be changed to pplayer->capital_tile. Maybe we can just pass the string name of the city here. Nothing else comes to mind offhand but I imagine we'll run into similar issues on the way. -jason ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#40080) replace city id with tile pointer or index
http://bugs.freeciv.org/Ticket/Display.html?id=40080 > > [wsimpson - Tue Feb 05 13:29:46 2008]: > I've found a serious overflow bug already. The ids are unsigned short, the > range is 65536 numbers, but ai/aidata.c allocates all players arrays with: > > /* max size of a short */ > #define MAX_NUM_ID 32767 > > BV_DEFINE(bv_id, MAX_NUM_ID); > > BV_SET(ai->stats.diplomat_reservations, pcity->id); That's really ludicrous. First of all, unless IDs are recycled there is no theoretical limit on the highest ID. There is a limit on the total number of cities available at once, that being 1/4 the number of tiles (or possibly equal to the number of tiles, in some cases). Having a massive array to index what is basically a hash value is incredibly wasteful. Assuming doing a lookup into pcity->ai->diplomat_reservation boolean value is too slow (which is I assume why the BV is used), it would be appropriate to change the BV immediately to do a lookup by tile index. As for the general change, Mike has a good point that there could be hidden risks in making this conversion. If the conversion IS done, however, it should be as simple as simply removing the pcity->id value completely, seeing what breaks, and replacing those breakages with the use of pcity->tile->index. -jason ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#40080) [tracking] replace city id with tile pointer or index
http://bugs.freeciv.org/Ticket/Display.html?id=40080 > William Allen Simpson wrote: > There are at least 148 *city->id references in 44 files (and untold others > with other pointer names). > This is a seriously daunting task! The agents.c code passes city ids around. 284 references to homecity in 56 files (is a city id) 408 references to *city->tile in 60 files (the proposed replacement for id) 548 references to *unit->tile in 63 files (distinguished from homecity) Therefore, this is now a tracking ticket for the series of changes to make this happen over time ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#40083) Server crash 5
http://bugs.freeciv.org/Ticket/Display.html?id=40083 > Christian Knoke wrote on Feb 05, 06:21 (-0800): > civserver crashes on every start of any scenario game, except "Earth, > medium, classic". Wrong again, its the client not the server, backtrace for the records. Christian Core was generated by `civclient'. Program terminated with signal 11, Segmentation fault. #0 terrain_name_translation (pterrain=0x0) at terrain.c:207 207 if (NULL == pterrain->name.translated) { (gdb) bt full #0 terrain_name_translation (pterrain=0x0) at terrain.c:207 No locals. #1 0x080ee997 in tile_get_info_text (ptile=0x946b928, linebreaks=0) at tile.c:644 pollution = lb = s = "Deciduous forest", '\0' #2 0x0807fae3 in get_unit_info_label_text2 (punits=0x8b59c08, linebreaks=0) at text.c:758 pcity = (struct city *) 0x0 infracount = count = str = {str = 0x8a21738 "Moves: 1", n = 9, n_alloc = 37} #3 0x081216d2 in update_unit_info_label (punits=0x8b59c08) at mapview.c:214 label = (GtkWidget *) 0x8a17010 #4 0x080609f7 in set_unit_focus (punit=0x951f1a8) at control.c:374 focus_changed = true __PRETTY_FUNCTION__ = "set_unit_focus" #5 0x08060d1e in advance_unit_focus () at control.c:523 candidate = (struct unit *) 0x951f1a8 num_units_in_old_focus = 0 #6 0x0807448e in handle_unit_packet_common (packet_unit=0x9571988) at packhand.c:1335 pcity = pcity = punit = (struct unit *) 0x951f1a8 need_update_menus = false repaint_unit = false repaint_city = false old_tile = (struct tile *) 0x0 check_focus = false moved = false #7 0x080748f0 in handle_unit_info (packet=0x959b0b8) at packhand.c:1030 punit = (struct unit *) 0x9571988 #8 0x08077838 in client_handle_packet (type=PACKET_PROCESSING_STARTED, packet=0xbfbd899a) at packhand_gen.c:136 No locals. #9 0x08058bc9 in client_packet_input (packet=0x959b0b8, type=49) at civclient.c:442 No locals. #10 0x0805cba3 in input_from_server (fd=4) at clinet.c:385 result = true packet = (void *) 0x959b0b8 type = PACKET_UNIT_INFO __PRETTY_FUNCTION__ = "input_from_server" #11 0xb7c0a28e in gdk_input_add () from /usr/lib/libgdk-x11-2.0.so.0 No symbol table info available. #12 0xb792cc7f in g_io_channel_unix_get_fd () from /usr/lib/libglib-2.0.so.0 No symbol table info available. #13 0xb7903731 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0 No symbol table info available. #14 0xb79067a6 in g_main_context_check () from /usr/lib/libglib-2.0.so.0 No symbol table info available. #15 0xb7906b67 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0 No symbol table info available. #16 0xb7d9a281 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0 No symbol table info available. #17 0x0811844b in ui_main (argc=1, argv=0xbfbd9474) at gui_main.c:1538 w = home = sig = style = #18 0x080592e1 in main (argc=Cannot access memory at address 0x1 ) at civclient.c:401 i = 1 loglevel = 2 ui_options = ui_separator = 247 option = user_tileset = 183 (gdb) -- Christian Knoke* * *http://cknoke.de * * * * * * * * * Ceterum censeo Microsoft esse dividendum. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#40083) Server crash 5
http://bugs.freeciv.org/Ticket/Display.html?id=40083 > S2_2 svn rev 14385 05 FEB 2008 GTK2 civserver crashes on every start of any scenario game, except "Earth, medium, classic". Christian -- Christian Knoke* * *http://cknoke.de * * * * * * * * * Ceterum censeo Microsoft esse dividendum. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#40082) string coding error in script.lua
http://bugs.freeciv.org/Ticket/Display.html?id=40082 > Christian Knoke wrote on Feb 05, 06:00 (-0800): > Patch attached. Forget it. It doesn't work. Christian -- Christian Knoke* * *http://cknoke.de * * * * * * * * * Ceterum censeo Microsoft esse dividendum. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#40082) string coding error in script.lua
http://bugs.freeciv.org/Ticket/Display.html?id=40082 > Christian Knoke wrote on Jan 31, 11:52 (+0100): > Jason Dorje Short wrote on Jan 30, 19:36 (-0500): > > On Jan 29, 2008 9:11 PM, William Allen Simpson > > <[EMAIL PROTECTED]> wrote: > > > Christian Knoke wrote: > > > > #: data/default/script.lua:30 > > > > #, fuzzy, c-format > > > > msgid "" > > > > "The %s have acquired %s from ancient scrolls of > > > > wisdom." > > > > > > > Some months ago, the 2.2 (then trunk) had the hut code moved to lua > > > scripts. > > > > > > Doesn't it work properly now? > > > > > > And why the long spaces? > > > > Properly marking strings in lua scripts for translation needs some > > consideration, last I checked. This should probably get (or has > > already) its own ticket. > > data/default/script.lua line 30 > > notify.embassies(owner, unit.tile, E.HUT_TECH, > _("The %s have acquired %s from ancient scrolls of\ > wisdom."), > owner.nation:plural_translation(), Patch attached. Christian -- Christian Knoke* * *http://cknoke.de * * * * * * * * * Ceterum censeo Microsoft esse dividendum. Index: data/default/script.lua === --- data/default/script.lua (Revision 14385) +++ data/default/script.lua (Arbeitskopie) @@ -27,8 +27,8 @@ _("You found %s in ancient scrolls of wisdom."), tech:name_translation()) notify.embassies(owner, unit.tile, E.HUT_TECH, - _("The %s have acquired %s from ancient scrolls of\ - wisdom."), + _("The %s have acquired %s from ancient scrolls of " + "wisdom."), owner.nation:plural_translation(), tech:name_translation()) return true ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#40080) replace city id with tile pointer or index
http://bugs.freeciv.org/Ticket/Display.html?id=40080 > There are at least 148 *city->id references in 44 files (and untold others with other pointer names). I've found a serious overflow bug already. The ids are unsigned short, the range is 65536 numbers, but ai/aidata.c allocates all players arrays with: /* max size of a short */ #define MAX_NUM_ID 32767 BV_DEFINE(bv_id, MAX_NUM_ID); BV_SET(ai->stats.diplomat_reservations, pcity->id); (Boom!) And the constant is wrong anyway, somebody forgot zero! This is fairly old code? Does anybody understand it? Do we need AI stats? ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#39563) [Bug] AI doesn't want to build anything (log)
http://bugs.freeciv.org/Ticket/Display.html?id=39563 > #defined LOG_WANT symbol, moved other local LOG_* to front of file Does not fix anything other than logging! Committed trunk revision 14384. Committed S2_2 revision 14385. Leaving open for future examination by others. This code is chock-a-block with FIXME and TODO comments. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#40080) replace city id with tile pointer or index
http://bugs.freeciv.org/Ticket/Display.html?id=40080 > In PR#40075, Jason Dorje Short wrote: > ... Why not just use the ptile->index as the city id? Cities > can't ever move and there can't ever be more than once city on a > tile...right? > ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#40075) S2_2 memory error in map_get_player_city
http://bugs.freeciv.org/Ticket/Display.html?id=40075 > Michael Kaufman wrote: > On Mon, Feb 04, 2008 at 07:49:58PM -0800, Jason Dorje Short wrote: >> ... Why not just use the ptile->index as the city id? ... > > ... > without knowing the tile location that the city sits on (the capital city?) > I really like Jason's idea. It might take time to implement, but it could ameliorate half a dozen recent bug reports that come to mind. And this would be a good time to eliminate the id field, as 2.2 will never generate savegames readable by earlier versions (because of new terrain). Since the id variable elimination will discover all existing uses, it's a good time to fix the latter, as well. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev