Whamcloud - gitweb
lib/{ext2fs,support}: fix 32-bit Windows build
[tools/e2fsprogs.git] / lib / ext2fs / badblocks.c
index 42e33bf..0f23983 100644 (file)
@@ -1,14 +1,15 @@
 /*
  * badblocks.c --- routines to manipulate the bad block structure
- * 
+ *
  * Copyright (C) 1994, 1995, 1996 Theodore Ts'o.
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #if HAVE_UNISTD_H
 #include "ext2_fs.h"
 #include "ext2fsP.h"
 
-#ifdef __arm__
-#define BUGGY_ARM_GCC
-#endif
-
 /*
  * Helper function for making a badblocks list
  */
@@ -38,7 +35,7 @@ static errcode_t make_u32_list(int size, int num, __u32 *list,
 {
        ext2_u32_list   bb;
        errcode_t       retval;
-       
+
        retval = ext2fs_get_mem(sizeof(struct ext2_struct_u32_list), &bb);
        if (retval)
                return retval;
@@ -46,19 +43,11 @@ static errcode_t make_u32_list(int size, int num, __u32 *list,
        bb->magic = EXT2_ET_MAGIC_BADBLOCKS_LIST;
        bb->size = size ? size : 10;
        bb->num = num;
-#ifdef BUGGY_ARM_GCC
-       bb->list = malloc(bb->size * sizeof(blk_t));
-       if (!bb->list) {
-               free(bb);
-               return EXT2_ET_NO_MEMORY;
-       }
-#else
-       retval = ext2fs_get_mem(bb->size * sizeof(blk_t), &bb->list);
-       if (!bb->list) {
+       retval = ext2fs_get_array(bb->size, sizeof(blk_t), &bb->list);
+       if (retval) {
                ext2fs_free_mem(&bb);
                return retval;
        }
-#endif
        if (list)
                memcpy(bb->list, list, bb->size * sizeof(blk_t));
        else
@@ -66,7 +55,7 @@ static errcode_t make_u32_list(int size, int num, __u32 *list,
        *ret = bb;
        return 0;
 }
-       
+
 
 /*
  * This procedure creates an empty u32 list.
@@ -91,7 +80,7 @@ errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret, int size)
 errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest)
 {
        errcode_t       retval;
-       
+
        retval = make_u32_list(src->size, src->num, src->list, dest);
        if (retval)
                return retval;
@@ -189,7 +178,7 @@ int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk)
                return high;
 
        while (low < high) {
-               mid = (low+high)/2;
+               mid = ((unsigned)low + (unsigned)high)/2;
                if (mid == low || mid == high)
                        break;
                if (blk == bb->list[mid])
@@ -283,11 +272,11 @@ int ext2fs_u32_list_iterate(ext2_u32_iterate iter, __u32 *blk)
 
        if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST)
                return 0;
-       
+
        if (iter->ptr < bb->num) {
                *blk = bb->list[iter->ptr++];
                return 1;
-       } 
+       }
        *blk = 0;
        return 0;
 }