aboutsummaryrefslogtreecommitdiff
path: root/src/util/strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/strings.c')
-rw-r--r--src/util/strings.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/util/strings.c b/src/util/strings.c
index 2ed1a0da3..40968956e 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -643,10 +643,10 @@ getValue__ (unsigned char a)
643 * @return pointer to the next byte in 'out' or NULL on error. 643 * @return pointer to the next byte in 'out' or NULL on error.
644 */ 644 */
645char * 645char *
646GNUNET_STRINGS_data_to_string (unsigned char *data, size_t size, char *out, size_t out_size) 646GNUNET_STRINGS_data_to_string (const unsigned char *data, size_t size, char *out, size_t out_size)
647{ 647{
648 /** 648 /**
649 * 32 characters for encoding (GNUNET_CRYPTO_hash => 32 characters) 649 * 32 characters for encoding
650 */ 650 */
651 static char *encTable__ = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; 651 static char *encTable__ = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
652 unsigned int wpos; 652 unsigned int wpos;
@@ -656,7 +656,11 @@ GNUNET_STRINGS_data_to_string (unsigned char *data, size_t size, char *out, size
656 656
657 GNUNET_assert (data != NULL); 657 GNUNET_assert (data != NULL);
658 GNUNET_assert (out != NULL); 658 GNUNET_assert (out != NULL);
659 GNUNET_assert (out_size >= (((size*8) + ((size*8) % 5)) % 5)); 659 if (out_size < (((size*8) + ((size*8) % 5)) % 5))
660 {
661 GNUNET_break (0);
662 return NULL;
663 }
660 vbit = 0; 664 vbit = 0;
661 wpos = 0; 665 wpos = 0;
662 rpos = 0; 666 rpos = 0;
@@ -675,12 +679,18 @@ GNUNET_STRINGS_data_to_string (unsigned char *data, size_t size, char *out, size
675 vbit = 5; 679 vbit = 5;
676 } 680 }
677 if (wpos >= out_size) 681 if (wpos >= out_size)
682 {
683 GNUNET_break (0);
678 return NULL; 684 return NULL;
685 }
679 out[wpos++] = encTable__[(bits >> (vbit - 5)) & 31]; 686 out[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
680 vbit -= 5; 687 vbit -= 5;
681 } 688 }
682 if (wpos != out_size) 689 if (wpos != out_size)
690 {
691 GNUNET_break (0);
683 return NULL; 692 return NULL;
693 }
684 GNUNET_assert (vbit == 0); 694 GNUNET_assert (vbit == 0);
685 return &out[wpos]; 695 return &out[wpos];
686} 696}