Re: [Freeciv-Dev] function genlist_size() causes game to crash after I've added new effect

2008-12-19 Thread Yoav Luft
Good morning for this side of the world...
My patch compiles against the latest trunk, and as far as can see, it
works, and even as expected. I only have to make the GTK GUI show some
relevant information, because currently it always shows that the
chance for a city to catch a plague is 0.
It seems that, as I have planned, my patch effectively keeps cities
from growing to large without certain improvements, while not setting
a fixed size. A city without an aqueduct is unlikely to grow above
size 8 for long. Haven't got to larger cities yet.
I'll send a newer patch in a couple of days or so, with a ruleset that
uses the new feature.

On 12/18/08, Madeline Book madeline.b...@gmail.com wrote:
 On 12/17/08, Yoav Luft yoav.l...@gmail.com wrote:
 Hi,
 I've written a little patch to the stable tree, as a way to acquaint
 myself with the code of freeciv.
 The patch adds the new functionality of plagues to game, which are
 determined randomly based on the size, pollution, improvements and
 trade routes of a city.
 The patch segfaults on me. I get that massage:
 Program received signal SIGSEGV, Segmentation fault.
 0x0041bd7d in pay_for_units (pplayer=0x861e18, pcity=0x1890fc0)
 at ../utility/speclist.h:110
 110   return genlist_size(tthis-list);

 it only happens when the game.info.plague_on is true, but I do not
 understand what genlist_size() does, or where and why it is called. It
 is my first attempt at adding code to freeciv, and I've spent some
 nights trying to understand what went wrong, but I'm kinda clueless.
 I guess it's not a bug, but rather a I didn't do something they it
 should be done, but I could find what that is.

 Attached is the patch.
 I will appreciate any help, even in explaining me what genlist_size does.

 The function genlist_size returns the size of a genlist which is a
 linked list of pointers. Genlists are used to implement speclists,
 which are just macro-generated interfaces to the genlist functions
 for specific data types (to avoid the type unsafe void pointers used
 by genlists). These data structures are defined in utility/genlist.h
 and utility/speclist.h.

 The particular segfault you have there is in all likelyhood caused
 by an operation on a NULL list somewhere; it would help if you
 looked at the entire backtrace to see the history of function calls.
 Then when you have a rough idea of where the NULL list might
 be, you can use gdb to step through the code or just insert some
 printfs (:D) to have the program tell you how far it gets before
 crashing. Once you pin point the location of the NULL access you
 can trace back the code path and find what caused the list to
 be NULL in the first place (you would check all the changes you
 made that get activated by your new setting).

 There is some information about using gdb for debugging here:
 http://freeciv.wikia.com/wiki/Bug_Reporting

 Also, I looked at your patch and it is actually not that bad at first
 glance. Granted you need to setup diff to ignore all those useless
 files that change every configure/make cycle, and setup your
 editor to follow the freeciv coding style more closely. Of course
 this is only if you intend to submit your patch for inclusion later.

 Here are some more helpful pages:
 http://freeciv.wikia.com/wiki/How_to_Contribute
 http://freeciv.wikia.com/wiki/Coding_Style

 Oh and by the way, you should implement new features on the
 trunk branch; the stable 2.1.x series is only getting bugfixes
 now.

 ---
 黒死病で死にたくない。

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#40605) timer_list_size() crash

2008-12-19 Thread Marko Lindqvist

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40605 

 2.1.8, using fantasy ruleset

Program terminated with signal 11, Segmentation fault.
[New process 20595]
#0  0x0042a01b in genlist_size ()
(gdb) bt full
#0  0x0042a01b in genlist_size ()
No locals.
#1  0x004e6e40 in timer_list_size ()
No locals.
#2  0x004e6d8d in close_connection ()
No locals.
#3  0x004e745b in incoming_client_packets ()
No locals.
#4  0x004e7f1e in server_sniff_all_input ()
No locals.
#5  0x00495255 in srv_main ()
No locals.
#6  0x00424dad in main ()
No locals.


 This is probably related to the fact that incoming connection was
rejected by auth code.


 I'm not sure if this is bug in official Freeciv. I have local
modification for prohibiting login with certain accounts, and bug
might be in that modification.


 - ML



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#40605) timer_list_size() crash

2008-12-19 Thread Madeline Book

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40605 

 [cazf...@gmail.com - Fri Dec 19 11:08:09 2008]:
 
  2.1.8, using fantasy ruleset
 
 Program terminated with signal 11, Segmentation fault.
 [New process 20595]
 #0  0x0042a01b in genlist_size ()
 (gdb) bt full
 #0  0x0042a01b in genlist_size ()
 No locals.
 #1  0x004e6e40 in timer_list_size ()
 No locals.
 #2  0x004e6d8d in close_connection ()
 No locals.
 [...]
 
  This is probably related to the fact that incoming connection was
 rejected by auth code.
 
 
  I'm not sure if this is bug in official Freeciv. I have local
 modification for prohibiting login with certain accounts, and bug
 might be in that modification.

I have seen a very similar backtrace in the past; this
is probably due to an attempted used of a NULL genlist.
The attached patches for S2_1 and trunk add checks for
the NULL list and should at least prevent crashing.


---
ピンポン!
diff --git a/server/sernet.c b/server/sernet.c
index 81d6493..b7ab4a5 100644
--- a/server/sernet.c
+++ b/server/sernet.c
@@ -116,6 +116,9 @@ static int socklan;
 #define SPECLIST_TAG timer
 #define SPECLIST_TYPE struct timer
 #include speclist.h
+#define timer_list_iterate(ARG_list, NAME_item) \
+  TYPED_LIST_ITERATE(struct timer, (ARG_list), NAME_item)
+#define timer_list_iterate_end LIST_ITERATE_END
 
 #define PROCESSING_TIME_STATISTICS 0
 
@@ -196,14 +199,18 @@ static void handle_readline_input_callback(char *line)
 */
 void close_connection(struct connection *pconn)
 {
-  while (timer_list_size(pconn-server.ping_timers)  0) {
-struct timer *timer = timer_list_get(pconn-server.ping_timers, 0);
+  if (!pconn) {
+return;
+  }
 
-timer_list_unlink(pconn-server.ping_timers, timer);
-free_timer(timer);
+  if (pconn-server.ping_timers != NULL) {
+timer_list_iterate(pconn-server.ping_timers, timer) {
+  free_timer(timer);
+} timer_list_iterate_end;
+timer_list_unlink_all(pconn-server.ping_timers);
+timer_list_free(pconn-server.ping_timers);
+pconn-server.ping_timers = NULL;
   }
-  assert(timer_list_size(pconn-server.ping_timers) == 0);
-  timer_list_free(pconn-server.ping_timers);
 
   /* safe to do these even if not in lists: */
   conn_list_unlink(game.all_connections, pconn);
diff --git a/utility/timing.c b/utility/timing.c
index 49337c8..ee2a6a1 100644
--- a/utility/timing.c
+++ b/utility/timing.c
@@ -213,7 +213,9 @@ struct timer *renew_timer_start(struct timer *t, enum timer_timetype type,
 ***/
 void free_timer(struct timer *t)
 {
-  free(t);
+  if (t != NULL) {
+free(t);
+  }
 }
 
 /** 
diff --git a/server/sernet.c b/server/sernet.c
index 055bff1..7f1a130 100644
--- a/server/sernet.c
+++ b/server/sernet.c
@@ -118,6 +118,9 @@ static int socklan;
 #define SPECLIST_TAG timer
 #define SPECLIST_TYPE struct timer
 #include speclist.h
+#define timer_list_iterate(ARG_list, NAME_item) \
+  TYPED_LIST_ITERATE(struct timer, (ARG_list), NAME_item)
+#define timer_list_iterate_end LIST_ITERATE_END
 
 #define PROCESSING_TIME_STATISTICS 0
 
@@ -198,16 +201,19 @@ static void handle_readline_input_callback(char *line)
 */
 void close_connection(struct connection *pconn)
 {
-  cancel_connection_votes(pconn);
+  if (!pconn) {
+return;
+  }
 
-  while (timer_list_size(pconn-server.ping_timers)  0) {
-struct timer *timer = timer_list_get(pconn-server.ping_timers, 0);
+  cancel_connection_votes(pconn);
 
-timer_list_unlink(pconn-server.ping_timers, timer);
-free_timer(timer);
+  if (pconn-server.ping_timers != NULL) {
+timer_list_iterate(pconn-server.ping_timers, timer) {
+  free_timer(timer);
+} timer_list_iterate_end;
+timer_list_free(pconn-server.ping_timers);
+pconn-server.ping_timers = NULL;
   }
-  assert(timer_list_size(pconn-server.ping_timers) == 0);
-  timer_list_free(pconn-server.ping_timers);
 
   /* safe to do these even if not in lists: */
   conn_list_unlink(game.all_connections, pconn);
diff --git a/utility/timing.c b/utility/timing.c
index 31ad317..66ac3d0 100644
--- a/utility/timing.c
+++ b/utility/timing.c
@@ -213,7 +213,9 @@ struct timer *renew_timer_start(struct timer *t, enum timer_timetype type,
 ***/
 void free_timer(struct timer *t)
 {
-  free(t);
+  if (t != NULL) {
+free(t);
+  }
 }
 
 /** 
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev