Skip to content

Commit 8fb205d

Browse files
authored
use g_realloc, not realloc (#4543)
plus improve some line breaks
1 parent 6fb70fa commit 8fb205d

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

libvips/iofuncs/source.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,7 @@ vips_source_print(VipsSource *source)
762762
printf(" source->data = %p\n", source->data);
763763
printf(" source->header_bytes = %p\n", source->header_bytes);
764764
if (source->header_bytes)
765-
printf(" source->header_bytes->len = %d\n",
766-
source->header_bytes->len);
765+
printf(" source->header_bytes->len = %d\n", source->header_bytes->len);
767766
printf(" source->sniff = %p\n", source->sniff);
768767
if (source->sniff)
769768
printf(" source->sniff->len = %d\n", source->sniff->len);
@@ -1250,8 +1249,7 @@ vips_source_seek(VipsSource *source, gint64 offset, int whence)
12501249
*/
12511250
if (new_pos < 0 ||
12521251
(source->length != -1 && new_pos > source->length)) {
1253-
vips_error(nick,
1254-
_("bad seek to %" G_GINT64_FORMAT), new_pos);
1252+
vips_error(nick, _("bad seek to %" G_GINT64_FORMAT), new_pos);
12551253
return -1;
12561254
}
12571255

libvips/iofuncs/util.c

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -744,25 +744,22 @@ vips__file_read(FILE *fp, const char *filename, size_t *length_out)
744744
if (len == -1) {
745745
int size;
746746

747-
/* Can't get length: read in chunks and realloc() to end of
747+
/* Can't get length: read in chunks and g_realloc() to end of
748748
* file.
749749
*/
750750
str = NULL;
751751
len = 0;
752752
size = 0;
753753
do {
754-
char *str2;
755-
756754
/* Again, a 1gb sanity limit.
757755
*/
758756
size += 1024;
759-
if (size > 1024 * 1024 * 1024 ||
760-
!(str2 = realloc(str, size))) {
761-
free(str);
757+
if (size > 1024 * 1024 * 1024) {
758+
g_free(str);
762759
vips_error("vips__file_read", "%s", _("out of memory"));
763760
return NULL;
764761
}
765-
str = str2;
762+
str = g_realloc(str, size);
766763

767764
/* -1 to allow space for an extra NULL we add later.
768765
*/
@@ -958,8 +955,7 @@ vips__gslist_gvalue_copy(const GSList *list)
958955
copy = NULL;
959956

960957
for (p = list; p; p = p->next)
961-
copy = g_slist_prepend(copy,
962-
vips__gvalue_copy((GValue *) p->data));
958+
copy = g_slist_prepend(copy, vips__gvalue_copy((GValue *) p->data));
963959

964960
copy = g_slist_reverse(copy);
965961

@@ -992,8 +988,7 @@ vips__gslist_gvalue_merge(GSList *a, const GSList *b)
992988
for (j = a; j; j = j->next) {
993989
GValue *value2 = (GValue *) j->data;
994990

995-
g_assert(G_VALUE_TYPE(value2) ==
996-
VIPS_TYPE_REF_STRING);
991+
g_assert(G_VALUE_TYPE(value2) == VIPS_TYPE_REF_STRING);
997992

998993
/* Just do a pointer compare ... good enough 99.9% of
999994
* the time.
@@ -1004,8 +999,7 @@ vips__gslist_gvalue_merge(GSList *a, const GSList *b)
1004999
}
10051000

10061001
if (!j)
1007-
tail = g_slist_prepend(tail,
1008-
vips__gvalue_copy(value));
1002+
tail = g_slist_prepend(tail, vips__gvalue_copy(value));
10091003
}
10101004

10111005
a = g_slist_concat(a, g_slist_reverse(tail));
@@ -1101,8 +1095,7 @@ vips__seek(int fd, gint64 pos, int whence)
11011095
gint64 new_pos;
11021096

11031097
if ((new_pos = vips__seek_no_error(fd, pos, whence)) == -1) {
1104-
vips_error_system(errno, "vips__seek",
1105-
"%s", _("unable to seek"));
1098+
vips_error_system(errno, "vips__seek", "%s", _("unable to seek"));
11061099
return -1;
11071100
}
11081101

@@ -1365,8 +1358,7 @@ vips__token_must(const char *p, VipsToken *token,
13651358
char *string, int size)
13661359
{
13671360
if (!(p = vips__token_get(p, token, string, size))) {
1368-
vips_error("get_token",
1369-
"%s", _("unexpected end of string"));
1361+
vips_error("get_token", "%s", _("unexpected end of string"));
13701362
return NULL;
13711363
}
13721364

@@ -1633,8 +1625,7 @@ vips__temp_name(const char *format)
16331625

16341626
int serial = g_atomic_int_add(&global_serial, 1);
16351627

1636-
g_snprintf(file, FILENAME_MAX, "vips-%d-%u",
1637-
serial, g_random_int());
1628+
g_snprintf(file, FILENAME_MAX, "vips-%d-%u", serial, g_random_int());
16381629
g_snprintf(file2, FILENAME_MAX, format, file);
16391630
name = g_build_filename(vips__temp_dir(), file2, NULL);
16401631

@@ -1960,8 +1951,7 @@ vips_icc_dir_once(void *null)
19601951
*/
19611952
char *windowsdir;
19621953

1963-
if ((windowsdir = g_utf16_to_utf8(wwindowsdir,
1964-
-1, NULL, NULL, NULL))) {
1954+
if ((windowsdir = g_utf16_to_utf8(wwindowsdir, -1, NULL, NULL, NULL))) {
19651955
gchar *full_path;
19661956

19671957
full_path = g_build_filename(windowsdir,
@@ -1981,8 +1971,7 @@ vips__icc_dir(void)
19811971
{
19821972
static GOnce once = G_ONCE_INIT;
19831973

1984-
return (const char *) g_once(&once,
1985-
vips_icc_dir_once, NULL);
1974+
return (const char *) g_once(&once, vips_icc_dir_once, NULL);
19861975
}
19871976

19881977
#ifdef G_OS_WIN32
@@ -2005,8 +1994,7 @@ vips__windows_prefix_once(void *null)
20051994
char *prefix;
20061995

20071996
#ifdef G_OS_WIN32
2008-
prefix = g_win32_get_package_installation_directory_of_module(
2009-
vips__dll);
1997+
prefix = g_win32_get_package_installation_directory_of_module(vips__dll);
20101998
#else /*!G_OS_WIN32*/
20111999
prefix = (char *) g_getenv("VIPSHOME");
20122000
#endif /*G_OS_WIN32*/
@@ -2019,8 +2007,7 @@ vips__windows_prefix(void)
20192007
{
20202008
static GOnce once = G_ONCE_INIT;
20212009

2022-
return (const char *) g_once(&once,
2023-
vips__windows_prefix_once, NULL);
2010+
return (const char *) g_once(&once, vips__windows_prefix_once, NULL);
20242011
}
20252012

20262013
char *

0 commit comments

Comments
 (0)