Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2005:
[Freeciv-Dev] (PR#14387) sizeof cleanup for common/
Home

[Freeciv-Dev] (PR#14387) sizeof cleanup for common/

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#14387) sizeof cleanup for common/
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 19 Oct 2005 15:08:35 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14387 >

This patch fixes sizeof calls in common/ to not use fixed types.

-jason

Index: common/unit.c
===================================================================
--- common/unit.c       (revision 11155)
+++ common/unit.c       (working copy)
@@ -1451,7 +1451,7 @@
                                  struct unit_type *punittype,
                                 int veteran_level)
 {
-  struct unit *punit = fc_calloc(1, sizeof(struct unit));
+  struct unit *punit = fc_calloc(1, sizeof(*punit));
 
   CHECK_UNIT_TYPE(punittype); /* No untyped units! */
   punit->type = punittype;
Index: common/tech.c
===================================================================
--- common/tech.c       (revision 11155)
+++ common/tech.c       (working copy)
@@ -743,7 +743,7 @@
 ***************************************************************/
 void player_research_init(struct player_research* research)
 {
-  memset(research, 0, sizeof(struct player_research));
+  memset(research, 0, sizeof(*research));
   research->tech_goal = A_UNSET;
   research->changed_from = -1;
 }
Index: common/dataio.c
===================================================================
--- common/dataio.c     (revision 11155)
+++ common/dataio.c     (working copy)
@@ -668,7 +668,7 @@
 
   dio_get_uint8(din, &count);
   if (values) {
-    *values = fc_malloc((count + 1) * sizeof(int));
+    *values = fc_malloc((count + 1) * sizeof(**values));
   }
   for (inx = 0; inx < count; inx++) {
     dio_get_uint8(din, values ? &((*values)[inx]) : NULL);
@@ -687,7 +687,7 @@
 
   dio_get_uint8(din, &count);
   if (values) {
-    *values = fc_malloc((count + 1) * sizeof(int));
+    *values = fc_malloc((count + 1) * sizeof(**values));
   }
   for (inx = 0; inx < count; inx++) {
     dio_get_uint16(din, values ? &((*values)[inx]) : NULL);
Index: common/diptreaty.c
===================================================================
--- common/diptreaty.c  (revision 11155)
+++ common/diptreaty.c  (working copy)
@@ -176,7 +176,7 @@
     }
   } clause_list_iterate_end;
    
-  pclause=(struct Clause *)fc_malloc(sizeof(struct Clause));
+  pclause = fc_malloc(sizeof(*pclause));
 
   pclause->type=type;
   pclause->from=pfrom;
Index: common/city.c
===================================================================
--- common/city.c       (revision 11155)
+++ common/city.c       (working copy)
@@ -2342,7 +2342,7 @@
 {
   int i;
 
-  city_styles = fc_calloc(num, sizeof(struct citystyle));
+  city_styles = fc_calloc(num, sizeof(*city_styles));
   game.control.styles_count = num;
 
   for (i = 0; i < game.control.styles_count; i++) {
@@ -2376,7 +2376,7 @@
   int i;
   struct city *pcity;
 
-  pcity = fc_malloc(sizeof(struct city));
+  pcity = fc_malloc(sizeof(*pcity));
 
   pcity->id = 0;
   assert(pplayer != NULL); /* No unowned cities! */
Index: common/worklist.c
===================================================================
--- common/worklist.c   (revision 11155)
+++ common/worklist.c   (working copy)
@@ -105,7 +105,8 @@
 ****************************************************************/
 void copy_worklist(struct worklist *dst, const struct worklist *src)
 {
-  memcpy(dst, src, sizeof(struct worklist));
+  assert(sizeof(*dst) == sizeof(*src));
+  memcpy(dst, src, sizeof(*dst));
 }
 
 /****************************************************************
Index: common/government.c
===================================================================
--- common/government.c (revision 11155)
+++ common/government.c (working copy)
@@ -166,9 +166,9 @@
   struct ruler_title *title;
 
   gov->num_ruler_titles++;
-  gov->ruler_titles =
-    fc_realloc(gov->ruler_titles,
-      gov->num_ruler_titles*sizeof(struct ruler_title));
+  gov->ruler_titles
+    = fc_realloc(gov->ruler_titles,
+                gov->num_ruler_titles * sizeof(*gov->ruler_titles));
   title = &(gov->ruler_titles[gov->num_ruler_titles-1]);
 
   title->nation = pnation; /* A valid nation or DEFAULT_NATION */
@@ -187,7 +187,7 @@
 {
   int index;
 
-  governments = fc_calloc(num, sizeof(struct government));
+  governments = fc_calloc(num, sizeof(*governments));
   game.control.government_count = num;
 
   for (index = 0; index < num; index++) {
Index: common/connection.c
===================================================================
--- common/connection.c (revision 11155)
+++ common/connection.c (working copy)
@@ -473,7 +473,7 @@
 {
   struct socket_packet_buffer *buf;
 
-  buf = (struct socket_packet_buffer *)fc_malloc(sizeof(*buf));
+  buf = fc_malloc(sizeof(*buf));
   buf->ndata = 0;
   buf->do_buffer_sends = 0;
   buf->nsize = 10*MAX_LEN_PACKET;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#14387) sizeof cleanup for common/, Jason Short <=