Complete.Org: Mailing Lists: Archives: freeciv-dev: May 1999:
[Freeciv-Dev] compiling under SunOS 4.1.3
Home

[Freeciv-Dev] compiling under SunOS 4.1.3

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] compiling under SunOS 4.1.3
From: Stamatogiannakis Manolis <mstamat@xxxxxxxxxx>
Date: Sun, 16 May 1999 13:41:26 +0300 (EET DST)

Hi there!
I compiled freeciv 1.8.0 on a sparc SunOS 4.1.3 machine,
using gcc version 2.8.1. There were a few problems I 
encountered (and solved) and I thought it would be good to report
them...

I send in attachment the output of the configure script.
If you want any other files that configure creates tell me.

Here we go then...

1
---
In file common/genlist.c I get the following error:
genlist.c:216: `NULL' undeclared (first use in this function)

To solve it, I just added the following two lines to the genlist.h file:
#include<stdio.h>
/* :-)  */


2
---
In file server/civserver.c I get the error:
civserver.c:293: `CLOCKS_PER_SEC' undeclared (first use in this function)

I checked and found that unlike linux's time.h, SunOS's time.h does
not defines CLOCKS_PER_SEC. So we add the following line to civserver.h:
#define CLOCKS_PER_SEC 1000000

(of course the number can be anything positive without causing serious 
problems, right?)


Now freeciv compiles!
So let's play...
Server works ok.
But the client dumps a core just after the window appears.
The core is in meswin_allocate function at messagewin.c:206.
After working a little with gdb we see that the the core is
dumped in the first call of the function.
It turns out that realloc does not work if the first argument is NULL.

A quick&easy solution for this is to add a static variable to check
if it is the first time that the function is called. 
The changed function is:

static void meswin_allocate(void)
{
  int i;

  /* new code starts here */
  static int first_time=1;

  if (first_time){
    messages_alloc = 100;
    string_ptrs = malloc(messages_alloc*sizeof(char*));
    xpos=malloc(messages_alloc*sizeof(int));
    ypos=malloc(messages_alloc*sizeof(int));
    first_time=0;
  }
  /* and ends here... */


  if (messages_total+2 > messages_alloc) {
    messages_alloc = messages_total + 32;
    string_ptrs = realloc(string_ptrs, messages_alloc*sizeof(char*));
    xpos = realloc(xpos, messages_alloc*sizeof(int));
    ypos = realloc(ypos, messages_alloc*sizeof(int));
    for( i=messages_total; i<messages_alloc; i++ ) {
      string_ptrs[i] = NULL;
      xpos[i] = 0;
      ypos[i] = 0;
    }
  }
}

It may be possible to add the mallocs where the function is called.
Now the client works ok!

4
---
Now we connect to the server, and try to start a game.
The server dumps a core on line 297 of server/registry.c file,
in parse_commalist function.
The problem is the same as problem 3.
realloc does not do what it *should* do.
So we have to check if entries->plist is NULL before realloc-ing.
If it is NULL we use malloc.

Now the server works ok and we can start the game.


5
---
When we start the game the client dumps a core again!
realloc is the cause again.
The core is dumped on genlist.c:234
The realloc that causes the trouble is on line 229 of genlist.c.
We check if sortbuf is NULL before realloc-ing and we use
malloc if it is NULL and now things are ok.


6
---
There are many other cases where realloc is used and cores are dumped.
I'll just stop here. If I can be any more help in fixing the problem,
just tell me what to do.


Thanx!

M.

Attachment: config.output
Description: Text document


[Prev in Thread] Current Thread [Next in Thread]