--- libaitio/src/Attic/patricia.c 2011/06/07 11:37:13 1.1.2.1 +++ libaitio/src/Attic/patricia.c 2012/05/23 11:49:35 1.4.8.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: patricia.c,v 1.1.2.1 2011/06/07 11:37:13 misho Exp $ +* $Id: patricia.c,v 1.4.8.1 2012/05/23 11:49:35 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -151,9 +151,10 @@ static char *prefix_toa2x(prefix_t *prefix, char *buff assert (prefix->bitlen <= 32); a = prefix_touchar(prefix); if (with_len) - sprintf(buff, "%d.%d.%d.%d/%d", a[0], a[1], a[2], a[3], prefix->bitlen); + snprintf(buff, with_len, "%d.%d.%d.%d/%d", a[0], a[1], a[2], + a[3], prefix->bitlen); else - sprintf(buff, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); + snprintf(buff, 16, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); return buff; } #ifdef HAVE_IPV6 @@ -162,7 +163,8 @@ static char *prefix_toa2x(prefix_t *prefix, char *buff a = (char*) inet_ntop(AF_INET6, &prefix->add.sin6, buff, 48 /* a guess value */); if (a && with_len) { assert(prefix->bitlen <= 128); - sprintf(buff + strlen(buff), "/%d", prefix->bitlen); + snprintf(buff + strlen(buff), with_len - strlen(buff), + "/%d", prefix->bitlen); } return buff; } @@ -180,7 +182,7 @@ static prefix_t *New_Prefix2(int family, void *dest, i if (family == AF_INET6) { default_bitlen = 128; if (!prefix) { - prefix = calloc(1, sizeof(prefix6_t)); + prefix = xcalloc(1, sizeof(prefix6_t)); dynamic_allocated++; } memcpy(&prefix->add.sin6, dest, 16); @@ -188,7 +190,7 @@ static prefix_t *New_Prefix2(int family, void *dest, i #endif /* HAVE_IPV6 */ if (family == AF_INET) { if (!prefix) { - prefix = calloc(1, sizeof(prefix4_t)); + prefix = xcalloc(1, sizeof(prefix4_t)); dynamic_allocated++; } memcpy(&prefix->add.sin, dest, 4); @@ -311,7 +313,7 @@ inline patricia_tree_t *New_Patricia(int maxbits) { patricia_tree_t *patricia; - patricia = calloc(1, sizeof *patricia); + patricia = xcalloc(1, sizeof *patricia); patricia->maxbits = maxbits; patricia->head = NULL; @@ -565,7 +567,7 @@ inline patricia_node_t *patricia_lookup(patricia_tree_ assert(prefix->bitlen <= patricia->maxbits); if (!patricia->head) { - node = calloc(1, sizeof *node); + node = xcalloc(1, sizeof *node); node->bit = prefix->bitlen; node->prefix = Ref_Prefix(prefix); node->parent = NULL; @@ -675,7 +677,7 @@ inline patricia_node_t *patricia_lookup(patricia_tree_ return node; } - new_node = calloc(1, sizeof *new_node); + new_node = xcalloc(1, sizeof *new_node); new_node->bit = prefix->bitlen; new_node->prefix = Ref_Prefix (prefix); new_node->parent = NULL; @@ -721,7 +723,7 @@ inline patricia_node_t *patricia_lookup(patricia_tree_ prefix_toa(prefix), prefix->bitlen); #endif /* PATRICIA_DEBUG */ } else { - glue = calloc(1, sizeof *glue); + glue = xcalloc(1, sizeof *glue); glue->bit = differ_bit; glue->prefix = NULL; glue->parent = node->parent;