Module Name: src Committed By: thorpej Date: Mon Jun 8 22:52:09 UTC 2020
Modified Files: src/sbin/gpt: backup.c Log Message: When we add "entries", "index", and "sector_size" values to the dictionary, add them as signed valaues, rather than unsigned (which is how we keep them in memory). This causes them be serialized in base-10 (rather than base-16, which is the default for unsigned). This behavior is documented in prop_number(3). Fixes t_gpt::backup_2part unit test. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sbin/gpt/backup.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/gpt/backup.c diff -u src/sbin/gpt/backup.c:1.19 src/sbin/gpt/backup.c:1.20 --- src/sbin/gpt/backup.c:1.19 Sun Jun 7 05:42:25 2020 +++ src/sbin/gpt/backup.c Mon Jun 8 22:52:09 2020 @@ -33,13 +33,15 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: backup.c,v 1.19 2020/06/07 05:42:25 thorpej Exp $"); +__RCSID("$NetBSD: backup.c,v 1.20 2020/06/08 22:52:09 thorpej Exp $"); #endif #include <sys/bootblock.h> #include <sys/types.h> +#include <assert.h> #include <err.h> +#include <limits.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> @@ -80,7 +82,8 @@ store_mbr(gpt_t gpt, unsigned int i, con mbr_dict = prop_dictionary_create(); PROP_ERR(mbr_dict); - PROP_ERR(prop_dictionary_set_uint(mbr_dict, "index", i)); + assert(i <= INT_MAX); + PROP_ERR(prop_dictionary_set_int(mbr_dict, "index", (int)i)); PROP_ERR(prop_dictionary_set_uint(mbr_dict, "flag", par->part_flag)); PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_head", par->part_shd)); @@ -127,8 +130,9 @@ store_gpt(gpt_t gpt, const struct gpt_hd le32toh(hdr->hdr_revision))); gpt_uuid_snprintf(buf, sizeof(buf), "%d", hdr->hdr_guid); PROP_ERR(prop_dictionary_set_string(*type_dict, "guid", buf)); - PROP_ERR(prop_dictionary_set_uint(*type_dict, "entries", - le32toh(hdr->hdr_entries))); + assert(le32toh(hdr->hdr_entries) <= INT32_MAX); + PROP_ERR(prop_dictionary_set_int32(*type_dict, "entries", + (int32_t)le32toh(hdr->hdr_entries))); return 0; cleanup: if (*type_dict) @@ -161,7 +165,8 @@ store_tbl(gpt_t gpt, const map_t m, prop m->map_size * gpt->secsz; i++, ent++) { gpt_dict = prop_dictionary_create(); PROP_ERR(gpt_dict); - PROP_ERR(prop_dictionary_set_uint(gpt_dict, "index", i)); + assert(i <= INT_MAX); + PROP_ERR(prop_dictionary_set_int(gpt_dict, "index", (int)i)); gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_type); PROP_ERR(prop_dictionary_set_string(gpt_dict, "type", buf)); gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_guid); @@ -206,7 +211,9 @@ backup(gpt_t gpt, const char *outfile) props = prop_dictionary_create(); PROP_ERR(props); - PROP_ERR(prop_dictionary_set_uint(props, "sector_size", gpt->secsz)); + assert(gpt->secsz <= INT_MAX); + PROP_ERR(prop_dictionary_set_int(props, "sector_size", + (int)gpt->secsz)); m = map_first(gpt); while (m != NULL) { switch (m->map_type) {