diff --git a/src/tofu.c b/src/tofu.c

index 0923aed3f3d9ac02a7bc6b81db965d6924e4af74..f63d37b8826d5641097402d4067df6a3460e9f77 100644

--- a/src/tofu.c

+++ b/src/tofu.c

@@ -79,8 +79,15 @@ }

char fingerprint[512 / 8 * 3];

for (size_t i = 0; i < sizeof(cc->hash); ++i) {

- snprintf(&fingerprint[i * 3], 4, "%02X%s",

- cc->hash[i], i + 1 == sizeof(cc->hash) ? "" : ":");

+ size_t l = 4;

+ const char *trail = ":";

+ /* Last entry. */

+ if (i + 1 == sizeof(cc->hash)) {

+ l = 3;

+ trail = "";

+ }

+ snprintf(&fingerprint[i * 3], l, "%02X%s",

+ cc->hash[i], trail);

}

enum tofu_error error = TOFU_UNTRUSTED_CERT;