|
From: Peter K. <pk...@us...> - 2001-03-26 14:02:11
|
The following file was modified in apps/bluetooth/sdp_server:
Name Old version New version Comment
---- ----------- ----------- -------
sdp_server.c 1.22 1.23=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* char2hex() now takes the result buffer as argument.
* get_values() uses a static buffer for its result.
* Removed two unnecessary malloc()'s and a memcpy() due to the two
changes above.=20
The diff of the modified file(s):
--- sdp_server.c 2001/03/26 13:48:28 1.22
+++ sdp_server.c 2001/03/26 14:02:09 1.23
@@ -119,7 +119,7 @@
#endif
=20
void start_xml_parser(XML_Parser p, int fd);
-unsigned char* char2hex(char *char_data);
+void char2hex(const char *char_data, unsigned char* buf);
char* get_values(char *value_string, int value_string_len, int fd);
void set_sdp_hdr(unsigned char *hdr, unsigned char pkt_type,
unsigned short trans_id, unsigned short len);
@@ -241,32 +241,25 @@
} while (len);
}
=20
-unsigned char*
-char2hex(char *char_data)
+void
+char2hex(const char *char_data, unsigned char* buf)
{
- int i =3D 0, m_size;
+ int i;
int tmp;
- unsigned char *hex_data;
-
- m_size =3D strlen(char_data) / 2;=20
- hex_data =3D malloc(m_size);
- D_MEM("---> malloc%d %ld bytes at 0x%8p", malloc_dbg++, m_size, hex_data=
);
=20
/* FIXME, How will this work when using big endian ? */
for (i =3D 0; i < strlen(char_data) / 2; i++)
{
sscanf(char_data + i * 2, "%02x", &tmp);
- hex_data[i] =3D (unsigned char)(tmp & 0xff);
+ buf[i] =3D (unsigned char)(tmp & 0xff);
}
-=20=20
- return hex_data;
}
=20
char*
get_values(char *value_string, int value_string_len, int fd)
{
int value_string_pos =3D 0;
- char *tmp_list;
+ static char tmp_list[256];
char tmp_len =3D 0;
char *des_pos[DES_HDR_DEPTH]; /* des stands for Data Elemet Sequence */
int des_len[DES_HDR_DEPTH];
@@ -285,9 +278,6 @@
des_pos[i] =3D NULL;
}
=20=20=20
- tmp_list =3D malloc(256);
- D_MEM("---> malloc%d %d bytes at 0x%8p", malloc_dbg++, 256, tmp_list);
-
/* While we have not reached the end of the string */
while (value_string_pos < value_string_len)
{
@@ -647,7 +637,6 @@
XML_Parser p;
char *return_sequence =3D NULL;
char *char_tmp =3D NULL;
- unsigned char *hex_tmp =3D NULL;
char tmp[12];
int len;
sdp_attribute_search search_struct;
@@ -703,19 +692,13 @@
char_tmp =3D get_values(search_struct.attrlist, search_struct.attrlist_i=
ndex, fd);
len =3D strlen(char_tmp) / 2;
=20
- hex_tmp =3D char2hex(char_tmp);
-
return_sequence =3D malloc(len + 2);
D_MEM("---> malloc%d %d bytes at 0x%8p", malloc_dbg++, len + 2, return_s=
equence);
=20=20=20
return_sequence[0] =3D 0x35;
return_sequence[1] =3D len;
- memcpy(return_sequence + 2, hex_tmp, len);
+ char2hex(char_tmp, return_sequence + 2);
=20=20=20
- D_MEM("<--- free%d 0x%8p", --malloc_dbg, char_tmp);
- free(char_tmp);
- D_MEM("<--- free%d 0x%8p", --malloc_dbg, hex_tmp);
- free(hex_tmp);
D_MEM("<--- free%d 0x%8p", --malloc_dbg, search_struct.attribute_name);
free(search_struct.attribute_name);
D_MEM("<--- free%d 0x%8p", --malloc_dbg, search_struct.service_class);
|