Module Name: src Committed By: christos Date: Sun Nov 29 00:15:12 UTC 2015
Modified Files: src/sbin/gpt: map.c Log Message: - use snprintf - fix bogus logic on map_type To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sbin/gpt/map.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/map.c diff -u src/sbin/gpt/map.c:1.7 src/sbin/gpt/map.c:1.8 --- src/sbin/gpt/map.c:1.7 Mon Sep 29 16:28:57 2014 +++ src/sbin/gpt/map.c Sat Nov 28 19:15:12 2015 @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/map.c,v 1.6 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: map.c,v 1.7 2014/09/29 20:28:57 christos Exp $"); +__RCSID("$NetBSD: map.c,v 1.8 2015/11/29 00:15:12 christos Exp $"); #endif #include <sys/types.h> @@ -42,6 +42,7 @@ __RCSID("$NetBSD: map.c,v 1.7 2014/09/29 #include <stdlib.h> #include "map.h" +#include "gpt.h" int lbawidth; @@ -52,7 +53,7 @@ mkmap(off_t start, off_t size, int type) { map_t *m; - m = malloc(sizeof(*m)); + m = calloc(1, sizeof(*m)); if (m == NULL) return (NULL); m->map_start = start; @@ -72,11 +73,15 @@ map_add(off_t start, off_t size, int typ n = mediamap; while (n != NULL && n->map_start + n->map_size <= start) n = n->map_next; - if (n == NULL) + if (n == NULL) { + if (!quiet) + warnx("Can't find map"); return (NULL); + } if (n->map_start + n->map_size < start + size) { - warnx("error: map entry doesn't fit media"); + if (!quiet) + warnx("map entry doesn't fit media"); return (NULL); } @@ -84,8 +89,9 @@ map_add(off_t start, off_t size, int typ if (n->map_type != MAP_TYPE_UNUSED) { if (n->map_type != MAP_TYPE_MBR_PART || type != MAP_TYPE_GPT_PART) { - warnx("warning: partition(%llu,%llu) mirrored", - (long long)start, (long long)size); + if (!quiet) + warnx("partition(%ju,%ju) mirrored", + (uintmax_t)start, (uintmax_t)size); } } n->map_type = type; @@ -93,13 +99,17 @@ map_add(off_t start, off_t size, int typ return (n); } - if (n->map_type != MAP_TYPE_UNUSED) { - if (n->map_type != MAP_TYPE_MBR_PART || - type != MAP_TYPE_GPT_PART) { - warnx("error: bogus map"); - return (0); - } + + switch (n->map_type) { + case MAP_TYPE_MBR_PART: + case MAP_TYPE_GPT_PART: n->map_type = MAP_TYPE_UNUSED; + break; + case MAP_TYPE_UNUSED: + break; + default: + warnx("bogus map %#x", n->map_type); + return (NULL); } m = mkmap(start, size, type); @@ -334,7 +344,7 @@ map_init(off_t size) char buf[32]; mediamap = mkmap(0LL, size, MAP_TYPE_UNUSED); - lbawidth = sprintf(buf, "%llu", (long long)size); + lbawidth = snprintf(buf, sizeof(buf), "%ju", (uintmax_t)size); if (lbawidth < 5) lbawidth = 5; }