]> git.proxmox.com Git - mirror_qemu.git/blobdiff - block-vvfat.c
Reset CFI01 flash wcycle after erase confirm (Thomas Petazzoni).
[mirror_qemu.git] / block-vvfat.c
index 08d426bbd565406d9e73f18bb279a2ecd525b6a9..79804a710782f6c541a862755060fcd281b32b7a 100644 (file)
@@ -93,7 +93,6 @@ static inline void array_free(array_t* array)
 
 /* does not automatically grow */
 static inline void* array_get(array_t* array,unsigned int index) {
-    assert(index >= 0);
     assert(index < array->next);
     return array->pointer + index * array->item_size;
 }
@@ -102,7 +101,7 @@ static inline int array_ensure_allocated(array_t* array, int index)
 {
     if((index + 1) * array->item_size > array->size) {
        int new_size = (index + 32) * array->item_size;
-       array->pointer = realloc(array->pointer, new_size);
+       array->pointer = qemu_realloc(array->pointer, new_size);
        if (!array->pointer)
            return -1;
        array->size = new_size;
@@ -128,7 +127,7 @@ static inline void* array_get_next(array_t* array) {
 static inline void* array_insert(array_t* array,unsigned int index,unsigned int count) {
     if((array->next+count)*array->item_size>array->size) {
        int increment=count*array->item_size;
-       array->pointer=realloc(array->pointer,array->size+increment);
+       array->pointer=qemu_realloc(array->pointer,array->size+increment);
        if(!array->pointer)
            return 0;
        array->size+=increment;
@@ -195,7 +194,6 @@ static int array_remove(array_t* array,int index)
 static int array_index(array_t* array, void* pointer)
 {
     size_t offset = (char*)pointer - array->pointer;
-    assert(offset >= 0);
     assert((offset % array->item_size) == 0);
     assert(offset/array->item_size < array->next);
     return offset/array->item_size;
@@ -1735,7 +1733,7 @@ static int check_directory_consistency(BDRVVVFATState *s,
     char path2[PATH_MAX];
 
     assert(path_len < PATH_MAX); /* len was tested before! */
-    strcpy(path2, path);
+    pstrcpy(path2, sizeof(path2), path);
     path2[path_len] = '/';
     path2[path_len + 1] = '\0';
 
@@ -1809,7 +1807,8 @@ DLOG(fprintf(stderr, "check direntry %d: \n", i); print_direntry(direntries + i)
                fprintf(stderr, "Name too long: %s/%s\n", path, lfn.name);
                goto fail;
            }
-           strcpy(path2 + path_len + 1, (char*)lfn.name);
+            pstrcpy(path2 + path_len + 1, sizeof(path2) - path_len - 1,
+                    (char*)lfn.name);
 
            if (is_directory(direntries + i)) {
                if (begin_of_direntry(direntries + i) == 0) {
@@ -2238,7 +2237,6 @@ static int commit_one_file(BDRVVVFATState* s,
 
        assert((size - offset == 0 && fat_eof(s, c)) ||
                (size > offset && c >=2 && !fat_eof(s, c)));
-       assert(size >= 0);
 
        ret = vvfat_read(s->bs, cluster2sector(s, c),
            (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);
@@ -2375,8 +2373,9 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s)
 
                            assert(!strncmp(m->path, mapping->path, l2));
 
-                           strcpy(new_path, mapping->path);
-                           strcpy(new_path + l1, m->path + l2);
+                            pstrcpy(new_path, l + diff + 1, mapping->path);
+                            pstrcpy(new_path + l1, l + diff + 1 - l1,
+                                    m->path + l2);
 
                            schedule_rename(s, m->begin, new_path);
                        }