safe the type convertion
This commit is contained in:
parent
246165b39e
commit
16aba8c9cb
|
|
@ -74,8 +74,8 @@ XDB_PUBLIC(int) xdb_search(xdb_searcher_t *xdb, unsigned int ip, char *region_bu
|
|||
xdb->io_count = 0;
|
||||
|
||||
// locate the segment index block based on the vector index
|
||||
il0 = (ip >> 24) & 0xFF;
|
||||
il1 = (ip >> 16) & 0xFF;
|
||||
il0 = ((int) (ip >> 24)) & 0xFF;
|
||||
il1 = ((int) (ip >> 16)) & 0xFF;
|
||||
idx = il0 * xdb_vector_index_cols * xdb_vector_index_size + il1 * xdb_vector_index_size;
|
||||
if (xdb->vector_index != NULL) {
|
||||
s_ptr = get_unsigned_int(xdb->vector_index, idx);
|
||||
|
|
@ -96,7 +96,7 @@ XDB_PUBLIC(int) xdb_search(xdb_searcher_t *xdb, unsigned int ip, char *region_bu
|
|||
// printf("s_ptr=%u, e_ptr=%u\n", s_ptr, e_ptr);
|
||||
// binary search to get the final region info
|
||||
data_len = 0, data_ptr = 0;
|
||||
l = 0, h = (e_ptr - s_ptr) / xdb_segment_index_size;
|
||||
l = 0, h = ((int) (e_ptr - s_ptr)) / xdb_segment_index_size;
|
||||
while (l <= h) {
|
||||
m = (l + h) >> 1;
|
||||
p = s_ptr + m * xdb_segment_index_size;
|
||||
|
|
@ -284,7 +284,7 @@ XDB_PUBLIC(unsigned int) get_unsigned_int(const char *buffer, int offset) {
|
|||
}
|
||||
|
||||
// get unsigned short (2bytes) from a specified buffer start from the specified offset
|
||||
XDB_PUBLIC(unsigned int) get_unsigned_short(const char *buffer, int offset) {
|
||||
XDB_PUBLIC(int) get_unsigned_short(const char *buffer, int offset) {
|
||||
return (
|
||||
((buffer[offset ]) & 0x000000FF) |
|
||||
((buffer[offset+1] << 8) & 0x0000FF00)
|
||||
|
|
|
|||
|
|
@ -23,14 +23,6 @@
|
|||
# define XDB_LINUX
|
||||
#endif
|
||||
|
||||
// memory allocation error
|
||||
#define XDB_ALLOCATE_ERROR(func, bytes) \
|
||||
do { \
|
||||
printf("<XDB>: Allocate Error In Function <%s> For %lu Bytes.\n", func, (unsigned long int) bytes); \
|
||||
return NULL; \
|
||||
} while (0);
|
||||
|
||||
|
||||
#define xdb_calloc( _blocks, _bytes ) calloc( _blocks, _bytes )
|
||||
#define xdb_malloc( _bytes ) malloc( _bytes )
|
||||
#define xdb_free( _ptr ) free( _ptr )
|
||||
|
|
@ -112,7 +104,7 @@ XDB_PUBLIC(char *) xdb_load_content_from_file(char *);
|
|||
XDB_PUBLIC(unsigned int) get_unsigned_int(const char *, int);
|
||||
|
||||
// get unsigned short (2bytes) from a specified buffer start from the specified offset with little-endian
|
||||
XDB_PUBLIC(unsigned int) get_unsigned_short(const char *, int);
|
||||
XDB_PUBLIC(int) get_unsigned_short(const char *, int);
|
||||
|
||||
// check the specified string ip and convert it to an unsigned int
|
||||
XDB_PUBLIC(int) check_ip(const char *, unsigned int *);
|
||||
|
|
|
|||
Loading…
Reference in New Issue