http://bugs.freeciv.org/Ticket/Display.html?id=15840 >
After investigation, I've discovered that the root cause was fixed without
updating this report at:
trunk:
r12014 | jdorje | 2006-06-09 15:25:19 -0400 (Fri, 09 Jun 2006) | 1 line
S2_1:
r12015 | jdorje | 2006-06-09 15:34:34 -0400 (Fri, 09 Jun 2006) | 1 line
S2_0:
r12160 | per | 2006-07-26 07:25:14 -0400 (Wed, 26 Jul 2006) | 2 lines
===
In addition, there were other trunk fixes prior to the S2_1 branch that
were not backported to S2_0 at:
r11174 | jdorje | 2005-10-22 14:55:21 -0400 (Sat, 22 Oct 2005) | 4 lines
Improve sizeof() calls to not use fixed types or casts.
Patch by me in PR#14387.
r10726 | jdorje | 2005-07-15 12:09:05 -0400 (Fri, 15 Jul 2005) | 4 lines
Use C99 stdint data types inside the network code.
Patch by me in PR#13464; requested by Benoit Hudson.
===
As for the additions in the proposed patch that serialize new fields in
dio_get_diplstate and dio_put_diplstate, that would not be backward
compatible with S2_0, and therefore ignored for these purposes.
S2_0 revision 13071.
Index: common/dataio.c
===
--- common/dataio.c (revision 13069)
+++ common/dataio.c (working copy)
@@ -25,6 +25,7 @@
#include
#include
+#include
#include
#include
#include
@@ -196,7 +197,7 @@
void dio_put_uint8(struct data_out *dout, int value)
{
if (enough_space(dout, 1)) {
-unsigned char x = value;
+uint8_t x = value;
assert(sizeof(x) == 1);
memcpy(ADD_TO_POINTER(dout->dest, dout->current), &x, 1);
@@ -210,7 +211,7 @@
void dio_put_uint16(struct data_out *dout, int value)
{
if (enough_space(dout, 2)) {
-unsigned short x = htons(value);
+uint16_t x = htons(value);
assert(sizeof(x) == 2);
memcpy(ADD_TO_POINTER(dout->dest, dout->current), &x, 2);
@@ -224,7 +225,7 @@
void dio_put_uint32(struct data_out *dout, int value)
{
if (enough_space(dout, 4)) {
-unsigned int x = htonl(value);
+uint32_t x = htonl(value);
assert(sizeof(x) == 4);
memcpy(ADD_TO_POINTER(dout->dest, dout->current), &x, 4);
@@ -406,7 +407,7 @@
{
if (enough_data(din, 1)) {
if (dest) {
- unsigned char x;
+ uint8_t x;
assert(sizeof(x) == 1);
memcpy(&x, ADD_TO_POINTER(din->src, din->current), 1);
@@ -423,7 +424,7 @@
{
if (enough_data(din, 2)) {
if (dest) {
- unsigned short x;
+ uint16_t x;
assert(sizeof(x) == 2);
memcpy(&x, ADD_TO_POINTER(din->src, din->current), 2);
@@ -440,7 +441,7 @@
{
if (enough_data(din, 4)) {
if (dest) {
- unsigned int x;
+ uint32_t x;
assert(sizeof(x) == 4);
memcpy(&x, ADD_TO_POINTER(din->src, din->current), 4);
@@ -472,7 +473,7 @@
**/
void dio_get_bool32(struct data_in *din, bool * dest)
{
- int ival;
+ int ival = 0;
dio_get_uint32(din, &ival);
@@ -505,7 +506,7 @@
**/
void dio_get_sint16(struct data_in *din, int *dest)
{
- int tmp;
+ int tmp = 0;
dio_get_uint16(din, &tmp);
if (dest) {
@@ -576,7 +577,7 @@
void dio_get_bit_string(struct data_in *din, char *dest,
size_t max_dest_size)
{
- int npack; /* number claimed in packet */
+ int npack = 0; /* number claimed in packet */
int i; /* iterate the bytes */
assert(dest != NULL && max_dest_size > 0);
@@ -673,7 +674,7 @@
dio_get_uint8(din, &count);
if (values) {
-*values = fc_malloc((count + 1) * sizeof(int));
+*values = fc_calloc((count + 1), sizeof(**values));
}
for (inx = 0; inx < count; inx++) {
dio_get_uint8(din, values ? &((*values)[inx]) : NULL);
@@ -692,7 +693,7 @@
dio_get_uint8(din, &count);
if (values) {
-*values = fc_malloc((count + 1) * sizeof(int));
+*values = fc_calloc((count + 1), sizeof(**values));
}
for (inx = 0; inx < count; inx++) {
dio_get_uint16(din, values ? &((*values)[inx]) : NULL);
@@ -702,6 +703,9 @@
}
}
+/**
+ De-serialize a player diplomatic state.
+**/
void dio_get_diplstate(struct data_in *din, struct player_diplstate *pds)
{
int type;
@@ -713,6 +717,9 @@
dio_get_uint8(din, &pds->has_reason_to_cancel);
}
+/**
+ Serialize a player diplomatic state.
+**/
void dio_put_diplstate(struct data_out *dout,
const struct player_diplstate *pds)
{
_