summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--riscos/bitmap.c16
-rw-r--r--riscos/filename.c29
2 files changed, 24 insertions, 21 deletions
diff --git a/riscos/bitmap.c b/riscos/bitmap.c
index 0acfa35dc..65668e563 100644
--- a/riscos/bitmap.c
+++ b/riscos/bitmap.c
@@ -168,7 +168,7 @@ struct bitmap *bitmap_create(int width, int height, bool clear)
if (width == 0 || height == 0)
return NULL;
- bitmap = calloc(sizeof(struct bitmap), 1);
+ bitmap = calloc(1, sizeof(struct bitmap));
if (!bitmap)
return NULL;
bitmap->width = width;
@@ -206,19 +206,19 @@ struct bitmap *bitmap_create_file(int width, int height, char *file)
struct bitmap *bitmap;
struct bitmap *link;
- if (width == 0 || height == 0)
+ if (width == 0 || height == 0 || file[0] == '\0')
return NULL;
if (!ro_filename_claim(file))
return NULL;
- bitmap = calloc(sizeof(struct bitmap), 1);
+ bitmap = calloc(1, sizeof(struct bitmap));
if (!bitmap)
return NULL;
bitmap->width = width;
bitmap->height = height;
bitmap->opaque = true;
bitmap->persistent = true;
- sprintf(bitmap->filename, file);
+ strcpy(bitmap->filename, file);
/* link into our list of bitmaps at the tail */
if (bitmap_head) {
@@ -247,7 +247,7 @@ bool bitmap_initialise(struct bitmap *bitmap, bool clear)
area_size = 16 + 44 + bitmap->width * bitmap->height * 4;
if (clear)
- bitmap->sprite_area = calloc(area_size, 1);
+ bitmap->sprite_area = calloc(1, area_size);
else
bitmap->sprite_area = malloc(area_size);
if (!bitmap->sprite_area) {
@@ -372,7 +372,7 @@ char *bitmap_get_buffer(struct bitmap *bitmap)
return ((char *) (bitmap->sprite_area)) + 16 + 44;
/* load and/or decompress the image */
- if (bitmap->filename && bitmap->filename[0])
+ if (bitmap->filename[0])
bitmap_load_file(bitmap);
if (bitmap->compressed)
bitmap_decompress(bitmap);
@@ -429,7 +429,7 @@ void bitmap_destroy(struct bitmap *bitmap)
}
if (bitmap->compressed)
free(bitmap->compressed);
- if (bitmap->filename && bitmap->filename[0])
+ if (bitmap->filename[0])
bitmap_delete_file(bitmap);
free(bitmap);
}
@@ -711,7 +711,7 @@ void bitmap_save_file(struct bitmap *bitmap)
assert(bitmap->compressed || bitmap->sprite_area);
/* unmodified bitmaps will still have their file available */
- if (!bitmap->modified && bitmap->filename && bitmap->filename[0]) {
+ if (!bitmap->modified && bitmap->filename[0]) {
if (bitmap->sprite_area)
free(bitmap->sprite_area);
bitmap->sprite_area = NULL;
diff --git a/riscos/filename.c b/riscos/filename.c
index 9355c4ffb..799ff3afd 100644
--- a/riscos/filename.c
+++ b/riscos/filename.c
@@ -86,9 +86,9 @@ bool ro_filename_claim(const char *filename) {
struct directory *dir;
/* extract the prefix */
- sprintf(dir_prefix, filename);
+ strcpy(dir_prefix, filename);
for (i = 0, last = dir_prefix; i < 3; i++)
- while (*last++ != '.');
+ while (*last && *last++ != '.');
i = atoi(last);
last[0] = '\0';
@@ -177,11 +177,9 @@ static struct directory *ro_filename_create_directory(const char *prefix) {
int result, index;
struct directory *old_dir, *new_dir, *prev_dir = NULL;
char dir_prefix[16];
-
+
/* get the lowest unique prefix, or use the provided one */
- if (prefix) {
- strcpy(dir_prefix, prefix);
- } else {
+ if (!prefix) {
sprintf(dir_prefix, "00.00.00.");
for (index = 1, old_dir = root; old_dir;
index++, old_dir = old_dir->next) {
@@ -192,8 +190,9 @@ static struct directory *ro_filename_create_directory(const char *prefix) {
((index >> 6) & 63),
((index >> 0) & 63));
}
+ prefix = dir_prefix;
}
-
+
/* allocate a new directory */
new_dir = (struct directory *)calloc(1,
sizeof(struct directory));
@@ -201,12 +200,13 @@ static struct directory *ro_filename_create_directory(const char *prefix) {
LOG(("No memory for calloc()"));
return NULL;
}
- strcpy(new_dir->prefix, dir_prefix);
+ strncpy(new_dir->prefix, prefix, 9);
+ new_dir->prefix[9] = '\0';
/* link into the tree, sorted by prefix. */
for (old_dir = root; old_dir; prev_dir = old_dir,
old_dir = old_dir->next) {
- result = strcmp(old_dir->prefix, dir_prefix);
+ result = strcmp(old_dir->prefix, prefix);
if (result == 0) {
free(new_dir);
return old_dir;
@@ -225,12 +225,15 @@ static struct directory *ro_filename_create_directory(const char *prefix) {
sprintf(ro_filename_directory, "%s.", CACHE_FILENAME_PREFIX);
last_1 = ro_filename_directory + strlen(CACHE_FILENAME_PREFIX) + 1;
last_2 = new_dir->prefix;
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < 3 && *last_2; i++) {
*last_1++ = *last_2++;
- while (*last_2 != '.')
+ while (*last_2 && *last_2 != '.')
*last_1++ = *last_2++;
- last_1[0] = '\0';
- xosfile_create_dir(ro_filename_directory, 0);
+ if (*last_2) {
+ last_1[0] = '\0';
+ xosfile_create_dir(ro_filename_directory, 0);
+ }
}
+
return new_dir;
}