mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
icon.c bug fix handle read errors
read errors are negative buf_sz was a unsignbed int Change-Id: I45ba67e09ce54ff09411248340ba2c9c62c57583
This commit is contained in:
parent
2ce7c716c3
commit
eafdba87f8
1 changed files with 38 additions and 28 deletions
|
@ -174,12 +174,14 @@ static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL};
|
||||||
static void load_icons(const char* filename, enum Iconset iconset,
|
static void load_icons(const char* filename, enum Iconset iconset,
|
||||||
enum screen_type screen)
|
enum screen_type screen)
|
||||||
{
|
{
|
||||||
int size_read;
|
ssize_t size_read;
|
||||||
|
ssize_t buf_size;
|
||||||
|
int fd;
|
||||||
int bmpformat = (FORMAT_ANY|FORMAT_DITHER|FORMAT_TRANSPARENT);
|
int bmpformat = (FORMAT_ANY|FORMAT_DITHER|FORMAT_TRANSPARENT);
|
||||||
struct iconset *ic = &iconsets[iconset][screen];
|
struct iconset *ic = &iconsets[iconset][screen];
|
||||||
int fd;
|
|
||||||
|
|
||||||
ic->loaded = false;
|
ic->loaded = false;
|
||||||
|
ic->handle = 0;
|
||||||
if (filename[0] && filename[0] != '-')
|
if (filename[0] && filename[0] != '-')
|
||||||
{
|
{
|
||||||
char path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
|
@ -188,29 +190,38 @@ static void load_icons(const char* filename, enum Iconset iconset,
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return;
|
return;
|
||||||
size_t buf_size = read_bmp_fd(fd, &ic->bmp, 0,
|
buf_size = read_bmp_fd(fd, &ic->bmp, 0,
|
||||||
bmpformat|FORMAT_RETURN_SIZE, NULL);
|
bmpformat|FORMAT_RETURN_SIZE, NULL);
|
||||||
ic->handle = core_alloc_ex(filename, buf_size, &buflib_ops);
|
if (buf_size > 0)
|
||||||
|
ic->handle = core_alloc_ex(filename, (size_t) buf_size, &buflib_ops);
|
||||||
|
|
||||||
if (ic->handle <= 0)
|
if (ic->handle <= 0)
|
||||||
{
|
{
|
||||||
close(fd);
|
/* error */
|
||||||
return;
|
goto finished;
|
||||||
}
|
}
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
ic->bmp.data = core_get_data(ic->handle);
|
ic->bmp.data = core_get_data(ic->handle);
|
||||||
|
|
||||||
ic->handle_locked = 1;
|
ic->handle_locked = 1;
|
||||||
size_read = read_bmp_fd(fd, &ic->bmp, buf_size, bmpformat, NULL);
|
size_read = read_bmp_fd(fd, &ic->bmp, buf_size, bmpformat, NULL);
|
||||||
close(fd);
|
|
||||||
ic->handle_locked = 0;
|
ic->handle_locked = 0;
|
||||||
|
|
||||||
|
if (size_read < 0)
|
||||||
|
{
|
||||||
|
/* error */
|
||||||
|
size_read = 0;
|
||||||
|
}
|
||||||
/* free unused alpha channel, if any */
|
/* free unused alpha channel, if any */
|
||||||
core_shrink(ic->handle, ic->bmp.data, size_read > 0 ? size_read : 0);
|
core_shrink(ic->handle, ic->bmp.data, size_read);
|
||||||
|
|
||||||
if (size_read <= 0)
|
if (size_read == 0)
|
||||||
ic->handle = core_free(ic->handle);
|
ic->handle = core_free(ic->handle);
|
||||||
else
|
else
|
||||||
ic->loaded = true;
|
ic->loaded = true;
|
||||||
|
finished:
|
||||||
|
close(fd);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,31 +245,30 @@ void icons_init(void)
|
||||||
{
|
{
|
||||||
load_icons(global_settings.icon_file, Iconset_user, SCREEN_MAIN);
|
load_icons(global_settings.icon_file, Iconset_user, SCREEN_MAIN);
|
||||||
|
|
||||||
if (global_settings.viewers_icon_file[0] &&
|
if (global_settings.viewers_icon_file[0] == '-' ||
|
||||||
global_settings.viewers_icon_file[0] != '-')
|
global_settings.viewers_icon_file[0] == '\0')
|
||||||
|
{
|
||||||
|
load_icons(DEFAULT_VIEWER_BMP, Iconset_viewers, SCREEN_MAIN);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
load_icons(global_settings.viewers_icon_file,
|
load_icons(global_settings.viewers_icon_file,
|
||||||
Iconset_viewers, SCREEN_MAIN);
|
Iconset_viewers, SCREEN_MAIN);
|
||||||
read_viewer_theme_file();
|
read_viewer_theme_file();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
load_icons(DEFAULT_VIEWER_BMP, Iconset_viewers, SCREEN_MAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
|
#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
|
||||||
load_icons(global_settings.remote_icon_file,
|
load_icons(global_settings.remote_icon_file,
|
||||||
Iconset_user, SCREEN_REMOTE);
|
Iconset_user, SCREEN_REMOTE);
|
||||||
|
|
||||||
if (global_settings.remote_viewers_icon_file[0] &&
|
if (global_settings.remote_viewers_icon_file[0] == '-' ||
|
||||||
global_settings.remote_viewers_icon_file[0] != '-')
|
global_settings.remote_viewers_icon_file[0] == '\0')
|
||||||
{
|
{
|
||||||
load_icons(global_settings.remote_viewers_icon_file,
|
load_icons(DEFAULT_REMOTE_VIEWER_BMP,
|
||||||
Iconset_viewers, SCREEN_REMOTE);
|
Iconset_viewers, SCREEN_REMOTE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
load_icons(DEFAULT_REMOTE_VIEWER_BMP,
|
load_icons(global_settings.remote_viewers_icon_file,
|
||||||
Iconset_viewers, SCREEN_REMOTE);
|
Iconset_viewers, SCREEN_REMOTE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue