|
From: Peter K. <pk...@us...> - 2001-03-26 15:52:28
|
The following files were modified in apps/bluetooth/sdp_server:
Name Old version New version Comment
---- ----------- ----------- -------
sdp_server.c 1.23 1.24=20=20=20=20=20=20=20=20=20=20=20=20
sdp_server.h 1.9 1.10=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* hdl_list_len and hdl_list_max (formerly block_len) now counts the
number of entries in the hdl_list in the rec_hdl_search_struct.
* Use realloc() instead of malloc() + memcpy() to add space to the
hdl_list in the rec_hdl_search_struct.
The diff of the modified file(s):
--- sdp_server.c 2001/03/26 14:02:09 1.23
+++ sdp_server.c 2001/03/26 15:52:26 1.24
@@ -287,7 +287,7 @@
strcpy(tmp_list + tmp_len, value_string + value_string_pos + 2);
tmp_len +=3D strlen(value_string + value_string_pos) - 2;
=20
- /* If we found a data element sequens header we need to remember that
+ /* If we found a data element sequence header we need to remember th=
at
position so we can fill in the length field later */=20=20=20=20=
=20=20
if (strncmp(value_string + value_string_pos, S_DES_HDR, strlen(S_DES=
_HDR)) =3D=3D 0)
{
@@ -296,8 +296,8 @@
i =3D (int) strtol(value_string + value_string_pos + strlen(S_DES_=
HDR),
NULL, 16);
=20
- /* Now we found a data element sequens header inside another
- data element sequense */
+ /* Now we found a data element sequence header inside another
+ data element sequence */
if (des_pos[i])
{
sprintf(c_des_len[i], "%02x", des_len[i]);
@@ -444,7 +444,7 @@
if ((s_hdl->tmp_hdl) && (strcmp(el, s_hdl->uuid) =3D=3D 0))
{
if ((s_hdl->hdl_list_len > 0) &&
- (s_hdl->tmp_hdl =3D=3D s_hdl->hdl_list[(s_hdl->hdl_list_len / U32_=
SIZE) - 1]))
+ (s_hdl->tmp_hdl =3D=3D s_hdl->hdl_list[s_hdl->hdl_list_len - 1]))
{
S_FNC("%s is present in record handle 0x%08x, but already found",
s_hdl->uuid, s_hdl->tmp_hdl);
@@ -458,23 +458,16 @@
necessary allocate new space for both the old and the new record
handles */
=20
- if (s_hdl->hdl_list_len >=3D s_hdl->block_len)
+ if (s_hdl->hdl_list_len >=3D s_hdl->hdl_list_max)
{
- tmp =3D s_hdl->hdl_list;
- s_hdl->block_len =3D s_hdl->hdl_list_len + s_hdl->block_len * 2;
- s_hdl->hdl_list =3D malloc(s_hdl->block_len);
- D_MEM("---> malloc%d %d bytes at 0x%8p", malloc_dbg++, s_hdl->bloc=
k_len, s_hdl->hdl_list);
+ s_hdl->hdl_list_max +=3D 16;
+ tmp =3D realloc(s_hdl->hdl_list, s_hdl->hdl_list_max * sizeof *s_h=
dl->hdl_list);
+ D_MEM("---> realloc%d %ld bytes at 0x%8p", malloc_dbg++, s_hdl->hd=
l_list_max * sizeof *s_hdl->hdl_list, tmp);
=20
- memcpy(s_hdl->hdl_list, tmp, s_hdl->hdl_list_len);
- if (tmp)
- {
- D_MEM("<--- free%d 0x%8p", --malloc_dbg, tmp);
- free(tmp);
- }
+ s_hdl->hdl_list =3D tmp;
}
=20=20=20=20=20
- s_hdl->hdl_list[s_hdl->hdl_list_len/sizeof(unsigned int)] =3D s_hdl-=
>tmp_hdl;
- s_hdl->hdl_list_len +=3D sizeof(unsigned int);
+ s_hdl->hdl_list[s_hdl->hdl_list_len++] =3D s_hdl->tmp_hdl;
}
}
}
@@ -490,7 +483,6 @@
rec_hdl_search_struct s_hdl;
char tmp_ch[12];
unsigned int *tmp;
- unsigned int tmp_len;
=20=20=20
XML_Parser p;
=20
@@ -514,8 +506,9 @@
}
=20
s_hdl.hdl_list_len =3D 0;
- s_hdl.block_len =3D 16 * sizeof(unsigned int);
- s_hdl.hdl_list =3D malloc(s_hdl.block_len);
+ s_hdl.hdl_list_max =3D 16;
+ s_hdl.hdl_list =3D malloc(s_hdl.hdl_list_max * sizeof *s_hdl.hdl_list);
+ D_MEM("---> malloc%d %ld bytes at 0x%8p", malloc_dbg++, s_hdl.hdl_list_m=
ax * sizeof *s_hdl.hdl_list, s_hdl.hdl_list);
=20=20=20
p =3D XML_ParserCreate(NULL);
XML_SetElementHandler(p, get_more_rec_hdl_start, get_more_rec_hdl_end);
@@ -525,24 +518,16 @@
start_xml_parser(p, fd);
XML_ParserFree(p);
=20
- if (s_hdl.hdl_list_len >=3D s_hdl.block_len)
+ if (s_hdl.hdl_list_len >=3D s_hdl.hdl_list_max)
{
- tmp =3D s_hdl.hdl_list;
- tmp_len =3D s_hdl.hdl_list_len + sizeof(unsigned int);
- s_hdl.block_len +=3D 1;
+ s_hdl.hdl_list_max =3D s_hdl.hdl_list_len + 1;
=20=20=20=20=20
- s_hdl.hdl_list =3D malloc(tmp_len);
- D_MEM("---> malloc%d %d bytes at 0x%8p", malloc_dbg++, tmp_len, s_hdl.=
hdl_list);
+ tmp =3D realloc(s_hdl.hdl_list, s_hdl.hdl_list_max * sizeof *s_hdl.hdl=
_list);
+ D_MEM("---> realloc%d %ld bytes at 0x%8p", malloc_dbg++, s_hdl.hdl_lis=
t_max * sizeof *s_hdl.hdl_list, tmp);
=20=20=20=20=20
- memcpy(s_hdl.hdl_list, tmp, s_hdl.hdl_list_len);
- if (tmp)
- {
- D_MEM("<--- free%d 0x%8p", --malloc_dbg, tmp);
- free(tmp);
- }
+ s_hdl.hdl_list =3D tmp;
}
- s_hdl.hdl_list[s_hdl.hdl_list_len / sizeof(unsigned int)] =3D NO_REC_HDL;
- s_hdl.hdl_list_len +=3D sizeof(unsigned int);
+ s_hdl.hdl_list[s_hdl.hdl_list_len++] =3D NO_REC_HDL;
=20=20=20
return s_hdl.hdl_list;
}
@@ -559,7 +544,6 @@
return_sequence =3D malloc(256);
D_MEM("---> malloc%d %d bytes at 0x%8p", malloc_dbg++, 256, return_seque=
nce);
=20=20=20
-=20=20
D_ATTR("A range of attributes was requested 0x%04x - 0x%04x",
(attr_id_code >> 16), (attr_id_code & 0xffff));
=20
@@ -774,7 +758,7 @@
}
}
}
- /* This is when we found a data element sequense, we here browses
+ /* This is when we found a data element sequence, we here browses
through all the attributes in the sequence and copies them into our
list */
else if (search_struct->attr2get > 0)
@@ -1276,7 +1260,7 @@
rsp_pkt[SDP_HDR_SIZE+1] =3D SHORT2CHAR_LS(rsp_pkt_len - SDP_HDR_SIZE - 2=
);
=20
/* The length of the attribute list is the length of the attribute byte
- count minus the size of the data element sequens header */
+ count minus the size of the data element sequence header */
rsp_pkt[des_len_pos] =3D rsp_pkt_len - SDP_HDR_SIZE - 2 - 2;
=20=20=20
set_sdp_hdr(rsp_pkt, SDP_SERVICEATTR_RSP, db_hdl->db.trans_id,
--- sdp_server.h 2001/03/26 12:25:24 1.9
+++ sdp_server.h 2001/03/26 15:52:26 1.10
@@ -73,8 +73,6 @@
=20
#define NO_REC_HDL 1
=20
-#define U32_SIZE sizeof(unsigned int)
-
#define SDP_ERROR_RSP 1
#define SDP_SERVICESEARCH_REQ 2
#define SDP_SERVICESEARCH_RSP 3
@@ -90,7 +88,7 @@
char *uuid;
unsigned int tmp_hdl;
unsigned int hdl_list_len;
- unsigned int block_len;
+ unsigned int hdl_list_max;
unsigned int *hdl_list;
} rec_hdl_search_struct;
=20
|