Commit 3a5a07fcd50fef63f9e3498a9a8af4910bc90e6d

Edward Thomson 2019-05-20T05:37:16

idxmap: safely cast down to khiter_t

diff --git a/src/idxmap.c b/src/idxmap.c
index e75887c..4dcf963 100644
--- a/src/idxmap.c
+++ b/src/idxmap.c
@@ -70,7 +70,8 @@ void git_idxmap_icase_clear(git_idxmap_icase *map)
 
 int git_idxmap_resize(git_idxmap *map, size_t size)
 {
-	if (kh_resize(idx, map, size) < 0) {
+	if (!git__is_uint32(size) ||
+	    kh_resize(idx, map, (khiter_t)size) < 0) {
 		git_error_set_oom();
 		return -1;
 	}
@@ -79,7 +80,8 @@ int git_idxmap_resize(git_idxmap *map, size_t size)
 
 int git_idxmap_icase_resize(git_idxmap_icase *map, size_t size)
 {
-	if (kh_resize(idxicase, map, size) < 0) {
+	if (!git__is_uint32(size) ||
+	    kh_resize(idxicase, map, (khiter_t)size) < 0) {
 		git_error_set_oom();
 		return -1;
 	}