diff options
author | TingPing <tingping@tingping.se> | 2014-12-28 06:37:25 -0500 |
---|---|---|
committer | TingPing <tingping@tingping.se> | 2014-12-28 06:44:44 -0500 |
commit | 83032b1aa3c3e5910c5cfd3e0ea1d25827f56475 (patch) | |
tree | 9be32a04d3070eac82177e11d182dad40a63baa7 /src/fe-gtk/palette.c | |
parent | c4cb1b25ec06a5b0cb718c6f8e74630df9a9bc64 (diff) |
Use glib for all allocations
- Removes need to check for malloc failure - Removes need for NULL checks on free - Adds checks for integer overflows - Removes some extra memset calls - Removes chance of mixing libc and glib malloc/free
Diffstat (limited to 'src/fe-gtk/palette.c')
-rw-r--r-- | src/fe-gtk/palette.c | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/src/fe-gtk/palette.c b/src/fe-gtk/palette.c index 435ba84b..0e933051 100644 --- a/src/fe-gtk/palette.c +++ b/src/fe-gtk/palette.c @@ -106,7 +106,7 @@ palette_alloc (GtkWidget * widget) void palette_load (void) { - int i, j, l, fh; + int i, j, fh; char prefname[256]; struct stat st; char *cfg; @@ -116,35 +116,29 @@ palette_load (void) if (fh != -1) { fstat (fh, &st); - cfg = malloc (st.st_size + 1); - if (cfg) + cfg = g_malloc0 (st.st_size + 1); + read (fh, cfg, st.st_size); + + /* mIRC colors 0-31 are here */ + for (i = 0; i < 32; i++) { - cfg[0] = '\0'; - l = read (fh, cfg, st.st_size); - if (l >= 0) - cfg[l] = '\0'; - - /* mIRC colors 0-31 are here */ - for (i = 0; i < 32; i++) - { - snprintf (prefname, sizeof prefname, "color_%d", i); - cfg_get_color (cfg, prefname, &red, &green, &blue); - colors[i].red = red; - colors[i].green = green; - colors[i].blue = blue; - } - - /* our special colors are mapped at 256+ */ - for (i = 256, j = 32; j < MAX_COL+1; i++, j++) - { - snprintf (prefname, sizeof prefname, "color_%d", i); - cfg_get_color (cfg, prefname, &red, &green, &blue); - colors[j].red = red; - colors[j].green = green; - colors[j].blue = blue; - } - free (cfg); + snprintf (prefname, sizeof prefname, "color_%d", i); + cfg_get_color (cfg, prefname, &red, &green, &blue); + colors[i].red = red; + colors[i].green = green; + colors[i].blue = blue; + } + + /* our special colors are mapped at 256+ */ + for (i = 256, j = 32; j < MAX_COL+1; i++, j++) + { + snprintf (prefname, sizeof prefname, "color_%d", i); + cfg_get_color (cfg, prefname, &red, &green, &blue); + colors[j].red = red; + colors[j].green = green; + colors[j].blue = blue; } + g_free (cfg); close (fh); } } |