diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-22 14:06:35 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-22 14:06:41 +0100 |
commit | 568dcc7b48238a0df22707dadb93f0f5b62c06b7 (patch) | |
tree | cfda9dca10137cf57b398a6ed4b9549b5ec68ddc /src/cadet/gnunet-service-cadet-new_paths.c | |
parent | da6e9cb613c7469798fdb004af59120e3f604343 (diff) | |
download | gnunet-568dcc7b48238a0df22707dadb93f0f5b62c06b7.tar.gz gnunet-568dcc7b48238a0df22707dadb93f0f5b62c06b7.zip |
make GCPP_2s also return static string
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_paths.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet-new_paths.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_paths.c b/src/cadet/gnunet-service-cadet-new_paths.c index aff46db07..bbe9af8b4 100644 --- a/src/cadet/gnunet-service-cadet-new_paths.c +++ b/src/cadet/gnunet-service-cadet-new_paths.c | |||
@@ -627,6 +627,7 @@ struct CadetPeer * | |||
627 | GCPP_get_peer_at_offset (struct CadetPeerPath *path, | 627 | GCPP_get_peer_at_offset (struct CadetPeerPath *path, |
628 | unsigned int off) | 628 | unsigned int off) |
629 | { | 629 | { |
630 | GNUNET_assert (off < path->entries_length); | ||
630 | return path->entries[off].peer; | 631 | return path->entries[off].peer; |
631 | } | 632 | } |
632 | 633 | ||
@@ -637,26 +638,34 @@ GCPP_get_peer_at_offset (struct CadetPeerPath *path, | |||
637 | * @param path path to convert | 638 | * @param path path to convert |
638 | * @return string, to be freed by caller (unlike other *_2s APIs!) | 639 | * @return string, to be freed by caller (unlike other *_2s APIs!) |
639 | */ | 640 | */ |
640 | char * | 641 | const char * |
641 | GCPP_2s (struct CadetPeerPath *path) | 642 | GCPP_2s (struct CadetPeerPath *path) |
642 | { | 643 | { |
643 | char *s; | 644 | static char buf[2048]; |
644 | char *old; | 645 | size_t off; |
646 | const unsigned int max_plen = sizeof(buf) / 5 - 2; /* 5 characters per entry */ | ||
645 | 647 | ||
646 | old = GNUNET_strdup (""); | 648 | off = 0; |
647 | for (unsigned int i = 0; | 649 | for (unsigned int i = 0; |
648 | i < path->entries_length; | 650 | i < path->entries_length; |
649 | i++) | 651 | i++) |
650 | { | 652 | { |
651 | GNUNET_asprintf (&s, | 653 | if ( (path->entries_length > max_plen) && |
652 | "%s %s", | 654 | (i == max_plen / 2) ) |
653 | old, | 655 | off += GNUNET_snprintf (&buf[off], |
654 | GNUNET_i2s (GCP_get_id (GCPP_get_peer_at_offset (path, | 656 | sizeof (buf) - off, |
655 | i)))); | 657 | "... "); |
656 | GNUNET_free_non_null (old); | 658 | if ( (path->entries_length > max_plen) && |
657 | old = s; | 659 | (i > max_plen / 2) && |
660 | (i < path->entries_length - max_plen / 2) ) | ||
661 | continue; | ||
662 | off += GNUNET_snprintf (&buf[off], | ||
663 | sizeof (buf) - off, | ||
664 | "%s ", | ||
665 | GNUNET_i2s (GCP_get_id (GCPP_get_peer_at_offset (path, | ||
666 | i)))); | ||
658 | } | 667 | } |
659 | return old; | 668 | return buf; |
660 | } | 669 | } |
661 | 670 | ||
662 | 671 | ||