commit - 01986ce9001e81cf428f546081a6888c518a54cc
commit + dc43cdc9c619cfe64774791cffda578d9c0f6e8d
blob - 3f1873d64f1c63ef2dc44534ddb9874a56c23447
blob + afcfed5fde3a472bae8c325446833512579d1125
--- include/got_error.h
+++ include/got_error.h
*/
struct got_object_id; /* forward declaration */
const struct got_error *got_error_no_obj(struct got_object_id *);
+
+/*
+ * Obtain an error with code GOT_ERR_OBJ_CSUM and an error message which
+ * contains the specified object ID. The message buffer is statically
+ * allocated; future invocations of this function will overwrite the
+ * message set during earlier invocations.
+ */
+const struct got_error *got_error_checksum(struct got_object_id *);
/*
* Obtain an error with code GOT_ERR_NOT_REF and an error message which
blob - 31a8aca5dcebc80f345a950a87d260a721e8e729
blob + fbfae58d5ac8823e5199dccfa6a0178dcb39965c
--- lib/error.c
+++ lib/error.c
return got_error(GOT_ERR_NO_OBJ);
return got_error_msg(GOT_ERR_NO_OBJ, msg);
+}
+
+const struct got_error *
+got_error_checksum(struct got_object_id *id)
+{
+ char id_str[GOT_OBJECT_ID_HEX_MAXLEN];
+ char msg[sizeof("checksum failure for object ") + sizeof(id_str)];
+ int ret;
+
+ if (!got_object_id_hex(id, id_str, sizeof(id_str)))
+ return got_error(GOT_ERR_OBJ_CSUM);
+
+ ret = snprintf(msg, sizeof(msg), "checksum failure for object %s",
+ id_str);
+ if (ret < 0 || (size_t)ret >= sizeof(msg))
+ return got_error(GOT_ERR_OBJ_CSUM);
+
+ return got_error_msg(GOT_ERR_OBJ_CSUM, msg);
}
const struct got_error *
blob - 6fc646eb18e40a9ccd26d08703df008856322e4e
blob + 7ddc0d0f970d44918913e45dc16467a1281efd26
--- lib/object_parse.c
+++ lib/object_parse.c
SHA1Final(sha1, &sha1_ctx);
if (memcmp(expected_id->sha1, sha1, SHA1_DIGEST_LENGTH) != 0) {
- char buf[SHA1_DIGEST_STRING_LENGTH];
- err = got_error_fmt(GOT_ERR_OBJ_CSUM,
- "checksum failure for object %s",
- got_sha1_digest_to_str(expected_id->sha1, buf,
- sizeof(buf)));
+ err = got_error_checksum(expected_id);
goto done;
}
SHA1Final(id.sha1, &sha1_ctx);
if (got_object_id_cmp(expected_id, &id) != 0) {
- char buf[SHA1_DIGEST_STRING_LENGTH];
- err = got_error_fmt(GOT_ERR_OBJ_CSUM,
- "checksum failure for object %s",
- got_sha1_digest_to_str(expected_id->sha1, buf,
- sizeof(buf)));
+ err = got_error_checksum(expected_id);
goto done;
}
SHA1Final(id.sha1, &sha1_ctx);
if (got_object_id_cmp(expected_id, &id) != 0) {
- char buf[SHA1_DIGEST_STRING_LENGTH];
- err = got_error_fmt(GOT_ERR_OBJ_CSUM,
- "checksum failure for object %s",
- got_sha1_digest_to_str(expected_id->sha1, buf,
- sizeof(buf)));
+ err = got_error_checksum(expected_id);
goto done;
}
SHA1Final(id.sha1, &sha1_ctx);
if (got_object_id_cmp(expected_id, &id) != 0) {
- char buf[SHA1_DIGEST_STRING_LENGTH];
- err = got_error_fmt(GOT_ERR_OBJ_CSUM,
- "checksum failure for object %s",
- got_sha1_digest_to_str(expected_id->sha1, buf,
- sizeof(buf)));
+ err = got_error_checksum(expected_id);
goto done;
}
blob - 5fa0499e9e024bcf6a7a8371640bb25e6032e5c5
blob + 278ffbba28800315d824bf942dd2a401bd045cb6
--- libexec/got-read-blob/got-read-blob.c
+++ libexec/got-read-blob/got-read-blob.c
#include "got_lib_object.h"
#include "got_lib_object_parse.h"
#include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
static volatile sig_atomic_t sigint_received;
}
SHA1Final(id.sha1, &sha1_ctx);
if (got_object_id_cmp(&expected_id, &id) != 0) {
- char buf[SHA1_DIGEST_STRING_LENGTH];
- err = got_error_fmt(GOT_ERR_OBJ_CSUM,
- "checksum failure for object %s",
- got_sha1_digest_to_str(expected_id.sha1, buf,
- sizeof(buf)));
+ err = got_error_checksum(&expected_id);
goto done;
}