From 54550ebb2a1fc504406b199550b8e023ef2c9517 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 1 Feb 2011 12:30:56 +0200 Subject: XDefaultOMIF.c: Fix memory leaks in get_font_name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of copying the value returned by get_prop_name and then releasing it, directly use the return value of get_prop_name, which allocates memory for the name. If get_prop_name returns NULL, continue on to XFreeFont to release the font before returning the NULL via the normal function return. Reviewed-by: Erkki Seppälä Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index dbadd90aa..6975aa806 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -381,7 +381,7 @@ get_font_name( XOC oc, char *pattern) { - char **list, *name, *prop_name; + char **list, *name; int count; XFontStruct *fs; Display *dpy = oc->core.om->core.display; @@ -397,13 +397,7 @@ get_font_name( fs = XLoadQueryFont(dpy, pattern); if (fs == NULL) return NULL; - prop_name = get_prop_name(dpy, fs); - if (prop_name == NULL) return NULL; - - name = (char*) Xmalloc(strlen(prop_name) + 1); - if (name) - strcpy(name, prop_name); - + name = get_prop_name(dpy, fs); XFreeFont(dpy, fs); } return name; -- cgit v1.2.3 From 7d7224d8543e85e3a34a1cddf99f3eac9aa9050b Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 12 Apr 2011 21:27:45 -0700 Subject: Replace Xmalloc+bzero pairs with Xcalloc calls Signed-off-by: Alan Coopersmith Reviewed-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 6975aa806..b74683aa7 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -128,10 +128,9 @@ init_fontset( data = XOM_GENERIC(oc->core.om)->data; - font_set = (FontSet) Xmalloc(sizeof(FontSetRec)); + font_set = Xcalloc(1, sizeof(FontSetRec)); if (font_set == NULL) return False; - bzero((char *) font_set, sizeof(FontSetRec)); gen = XOC_GENERIC(oc); gen->font_set = font_set; @@ -1005,10 +1004,9 @@ create_oc( { XOC oc; - oc = (XOC) Xmalloc(sizeof(XOCGenericRec)); + oc = Xcalloc(1, sizeof(XOCGenericRec)); if (oc == NULL) return (XOC) NULL; - bzero((char *) oc, sizeof(XOCGenericRec)); oc->core.om = om; @@ -1126,15 +1124,13 @@ add_data( XOMGenericPart *gen = XOM_GENERIC(om); OMData new; - new = (OMData) Xmalloc(sizeof(OMDataRec)); + new = Xcalloc(1, sizeof(OMDataRec)); if (new == NULL) return NULL; gen->data = new; - bzero((char *) new, sizeof(OMDataRec)); - return new; } @@ -1168,10 +1164,9 @@ init_om( if (data == NULL) return False; - font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count); + font_data = Xcalloc(count, sizeof(FontDataRec)); if (font_data == NULL) return False; - bzero((char *) font_data, sizeof(FontDataRec) * count); data->font_data = font_data; data->font_data_count = count; @@ -1237,10 +1232,9 @@ _XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb, { XOM om; - om = (XOM) Xmalloc(sizeof(XOMGenericRec)); + om = Xcalloc(1, sizeof(XOMGenericRec)); if (om == NULL) return (XOM) NULL; - bzero((char *) om, sizeof(XOMGenericRec)); om->methods = (XOMMethods)&methods; om->core.lcd = lcd; -- cgit v1.2.3 From dde00b2f6848a38e9fdbe1e4c85373c8b12944b4 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 12 Apr 2011 22:30:45 -0700 Subject: Convert malloc(strlen()); strcpy() sets to strdup Signed-off-by: Alan Coopersmith Reviewed-by: Jeremy Huddleston Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index b74683aa7..26c6c3a98 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -216,9 +216,8 @@ check_fontname( fname = prop_fname; } if (data) { - font_set->font_name = (char *) Xmalloc(strlen(fname) + 1); + font_set->font_name = strdup(fname); if (font_set->font_name) { - strcpy(font_set->font_name, fname); found_num++; } } @@ -387,9 +386,7 @@ get_font_name( list = XListFonts(dpy, pattern, 1, &count); if (list != NULL) { - name = (char *) Xmalloc(strlen(*list) + 1); - if (name) - strcpy(name, *list); + name = strdup(*list); XFreeFontNames(list); } else { @@ -459,13 +456,11 @@ parse_fontname( if (font_data == NULL) continue; - font_set->font_name = (char *) Xmalloc(strlen(font_name) + 1); + font_set->font_name = strdup(font_name); + Xfree(font_name); if (font_set->font_name == NULL) { - Xfree(font_name); goto err; } - strcpy(font_set->font_name, font_name); - Xfree(font_name); found_num++; goto found; } @@ -548,11 +543,10 @@ Limit the length of the string copy to prevent stack corruption. } } found: - base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1); + base_name = strdup(oc->core.base_name_list); if (base_name == NULL) goto err; - strcpy(base_name, oc->core.base_name_list); oc->core.base_name_list = base_name; XFreeStringList(name_list); @@ -1177,10 +1171,9 @@ This one is fine. *value points to one of the local strings in supported_charset_list[]. */ strcpy(buf, *value++); - font_data->name = (char *) Xmalloc(strlen(buf) + 1); + font_data->name = strdup(buf); if (font_data->name == NULL) return False; - strcpy(font_data->name, buf); } length += strlen(data->font_data->name) + 1; @@ -1241,16 +1234,14 @@ _XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb, om->core.display = dpy; om->core.rdb = rdb; if (res_name) { - om->core.res_name = (char *)Xmalloc(strlen(res_name) + 1); + om->core.res_name = strdup(res_name); if (om->core.res_name == NULL) goto err; - strcpy(om->core.res_name, res_name); } if (res_class) { - om->core.res_class = (char *)Xmalloc(strlen(res_class) + 1); + om->core.res_class = strdup(res_class); if (om->core.res_class == NULL) goto err; - strcpy(om->core.res_class, res_class); } if (om_resources[0].xrm_name == NULLQUARK) -- cgit v1.2.3 From bd43a06402b7499a74de0d4fb5ef8330b490b38f Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 3 Sep 2010 23:11:53 -0700 Subject: Sun's copyrights are now owned by Oracle Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 26c6c3a98..9e6feb76b 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -37,7 +37,7 @@ Sun Microsystems, Inc. or its licensors is granted. */ /* - * Copyright 2000 Sun Microsystems, Inc. All rights reserved. + * Copyright 2000 Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), -- cgit v1.2.3 From 22377a799a141ba6b1e43b83de4a506b36a842a4 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 13:37:53 -0700 Subject: init_om: remove unneeded extra copy of string to local buffer Strings from the supported_charset_list[] were being copied one by one to a stack buffer, and then strdup called on that buffer. Instead, just strdup the original string, without the local copy, and use a more traditional for loop, so it's easier to figure out what the code is doing (cleaning up a gcc const-cast warning in the process). Signed-off-by: Alan Coopersmith Reviewed-by: Matthieu Herrb Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 9e6feb76b..a8faa2af1 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -1148,10 +1148,9 @@ init_om( FontData font_data; char **required_list; XOrientation *orientation; - char **value, buf[BUFSIZ], *bufptr; - int count, length = 0; + char *bufptr; + int i, count, length = 0; - value = (char**)supported_charset_list; count = XlcNumber(supported_charset_list); data = add_data(om); @@ -1164,14 +1163,8 @@ init_om( data->font_data = font_data; data->font_data_count = count; - for ( ; count-- > 0; font_data++) { -/* -1266793 -This one is fine. *value points to one of the local strings in -supported_charset_list[]. -*/ - strcpy(buf, *value++); - font_data->name = strdup(buf); + for (i = 0; i < count; i++, font_data++) { + font_data->name = strdup(supported_charset_list[i]); if (font_data->name == NULL) return False; } -- cgit v1.2.3 From c161df4fee61819a28089682963cc2e721ca22c8 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Aug 2013 23:51:08 -0700 Subject: Remove even more casts of return values from Xmalloc/Xrealloc Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index a8faa2af1..71dc810eb 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -76,7 +76,7 @@ Sun Microsystems, Inc. or its licensors is granted. #define XOC_GENERIC(font_set) (&((XOCGeneric) font_set)->gen) #define DefineLocalBuf char local_buf[BUFSIZ] -#define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf) +#define AllocLocalBuf(length) (length > BUFSIZ ? Xmalloc(length) : local_buf) #define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr) typedef struct _FontDataRec { @@ -332,15 +332,15 @@ init_core_part( if (count == 0) return False; - font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *)); + font_struct_list = Xmalloc(sizeof(XFontStruct *)); if (font_struct_list == NULL) return False; - font_name_list = (char **) Xmalloc(sizeof(char *)); + font_name_list = Xmalloc(sizeof(char *)); if (font_name_list == NULL) goto err; - font_name_buf = (char *) Xmalloc(length); + font_name_buf = Xmalloc(length); if (font_name_buf == NULL) goto err; @@ -578,11 +578,11 @@ set_missing_list( if (count == 0) return True; - charset_list = (char **) Xmalloc(sizeof(char *)); + charset_list = Xmalloc(sizeof(char *)); if (charset_list == NULL) return False; - charset_buf = (char *) Xmalloc(length); + charset_buf = Xmalloc(length); if (charset_buf == NULL) { Xfree(charset_list); return False; @@ -1172,11 +1172,11 @@ init_om( length += strlen(data->font_data->name) + 1; /* required charset list */ - required_list = (char **) Xmalloc(sizeof(char *)); + required_list = Xmalloc(sizeof(char *)); if (required_list == NULL) return False; - bufptr = (char *) Xmalloc(length); + bufptr = Xmalloc(length); if (bufptr == NULL) { Xfree(required_list); return False; @@ -1192,7 +1192,7 @@ init_om( bufptr += strlen(bufptr) + 1; /* orientation list */ - orientation = (XOrientation *) Xmalloc(sizeof(XOrientation)); + orientation = Xmalloc(sizeof(XOrientation)); if (orientation == NULL) return False; -- cgit v1.2.3 From a98260726b8f878e72223899e21ad87882389e2d Mon Sep 17 00:00:00 2001 From: walter harms Date: Sat, 7 Jun 2014 15:17:27 +0200 Subject: libX11: rm redundante NULL checks This patch removes the last remaining NULL checks for Xfree() Signed-off-by: Harms Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 71dc810eb..6af1c8015 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -367,8 +367,8 @@ init_core_part( return True; err: - if (font_name_list) - Xfree(font_name_list); + + Xfree(font_name_list); Xfree(font_struct_list); return False; @@ -636,14 +636,10 @@ destroy_oc( XOCGenericPart *gen = XOC_GENERIC(oc); XFontStruct **font_list, *font; - if (gen->font_set) - Xfree(gen->font_set); - - if (oc->core.base_name_list) - Xfree(oc->core.base_name_list); - if (oc->core.font_info.font_name_list) - XFreeStringList(oc->core.font_info.font_name_list); + Xfree(gen->font_set); + Xfree(oc->core.base_name_list); + XFreeStringList(oc->core.font_info.font_name_list); if ((font_list = oc->core.font_info.font_struct_list)) { if ((font = *font_list)) { @@ -655,14 +651,12 @@ destroy_oc( Xfree(oc->core.font_info.font_struct_list); } - if (oc->core.missing_list.charset_list) - XFreeStringList(oc->core.missing_list.charset_list); + + XFreeStringList(oc->core.missing_list.charset_list); #ifdef notdef - if (oc->core.res_name) - Xfree(oc->core.res_name); - if (oc->core.res_class) - Xfree(oc->core.res_class); + Xfree(oc->core.res_name); + Xfree(oc->core.res_class); #endif Xfree(oc); @@ -1043,7 +1037,6 @@ close_om( if (data->font_data) { for (font_data = data->font_data, count = data->font_data_count; count-- > 0 ; font_data++) { - if (font_data->name) Xfree(font_data->name); } Xfree(data->font_data); @@ -1051,17 +1044,16 @@ close_om( Xfree(gen->data); } - if (om->core.res_name) - Xfree(om->core.res_name); - if (om->core.res_class) - Xfree(om->core.res_class); + + Xfree(om->core.res_name); + Xfree(om->core.res_class); + if (om->core.required_charset.charset_list) XFreeStringList(om->core.required_charset.charset_list); else Xfree((char*)om->core.required_charset.charset_list); - if (om->core.orientation_list.orientation) - Xfree(om->core.orientation_list.orientation); + Xfree(om->core.orientation_list.orientation); Xfree(om); return 1; -- cgit v1.2.3 From b912a4042d884ccc2f226ab80ddc7272967d58b2 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 4 Dec 2015 22:20:53 -0800 Subject: Delete #if 0 hunks of code Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 83 ------------------------------------------- 1 file changed, 83 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index 6af1c8015..f9469feca 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -182,61 +182,6 @@ check_charset( return (FontData) NULL; } -#if 0 /* Unused */ -static int -check_fontname( - XOC oc, - char *name) -{ - Display *dpy = oc->core.om->core.display; - XOCGenericPart *gen = XOC_GENERIC(oc); - FontData data; - FontSet font_set; - XFontStruct *fs_list; - char **fn_list, *fname, *prop_fname = NULL; - int list_num, i; - int list2_num; - char **fn2_list = NULL; - int found_num = 0; - - fn_list = XListFonts(dpy, name, MAXFONTS, &list_num); - if (fn_list == NULL) - return found_num; - - for (i = 0; i < list_num; i++) { - fname = fn_list[i]; - - font_set = gen->font_set; - - if ((data = check_charset(font_set, fname)) == NULL) { - if ((fn2_list = XListFontsWithInfo(dpy, name, MAXFONTS, - &list2_num, &fs_list)) - && (prop_fname = get_prop_name(dpy, fs_list)) - && (data = check_charset(font_set, prop_fname))) - fname = prop_fname; - } - if (data) { - font_set->font_name = strdup(fname); - if (font_set->font_name) { - found_num++; - } - } - if (fn2_list) { - XFreeFontInfo(fn2_list, fs_list, list2_num); - fn2_list = NULL; - if (prop_fname) { - Xfree(prop_fname); - prop_fname = NULL; - } - } - if (found_num == 1) - break; - } - XFreeFontNames(fn_list); - return found_num; -} -#endif - static Bool load_font( XOC oc) @@ -256,34 +201,6 @@ load_font( return True; } -#if 0 -static Bool -load_font_info( - XOC oc) -{ - Display *dpy = oc->core.om->core.display; - XOCGenericPart *gen = XOC_GENERIC(oc); - FontSet font_set = gen->font_set; - char **fn_list; - int fn_num; - - if (font_set->font_name == NULL) - return False; - - if (font_set->info == NULL) { - fn_list = XListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num, - &font_set->info); - if (font_set->info == NULL) - return False; - if (fn_num > 0) - font_set->info->fid = XLoadFont(dpy, font_set->font_name); - - if (fn_list) XFreeFontNames(fn_list); - } - return True; -} -#endif - static void set_fontset_extents( XOC oc) -- cgit v1.2.3 From c00196d2d178b4ed1866c18ccab76cbb941df6f0 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 09:46:31 -0800 Subject: XDefaultOMIF: replace strlen+Xmalloc+strcpy with strdup Code seems to have been originally written to handle appending multiple strings, but only ever operates on a single string. Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index f9469feca..f7b1b1d8c 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -237,13 +237,12 @@ init_core_part( FontSet font_set; XFontStruct **font_struct_list; char **font_name_list, *font_name_buf; - int count, length; + int count; font_set = gen->font_set; - count = length = 0; + count = 0; if (font_set->font_name != NULL) { - length += strlen(font_set->font_name) + 1; count++; } if (count == 0) @@ -257,7 +256,7 @@ init_core_part( if (font_name_list == NULL) goto err; - font_name_buf = Xmalloc(length); + font_name_buf = strdup(font_set->font_name); if (font_name_buf == NULL) goto err; @@ -273,7 +272,6 @@ init_core_part( *font_struct_list++ = font_set->font; else *font_struct_list++ = font_set->info; - strcpy(font_name_buf, font_set->font_name); Xfree(font_set->font_name); *font_name_list++ = font_set->font_name = font_name_buf; font_name_buf += strlen(font_name_buf) + 1; @@ -482,13 +480,12 @@ set_missing_list( XOCGenericPart *gen = XOC_GENERIC(oc); FontSet font_set; char **charset_list, *charset_buf; - int count, length; + int count; font_set = gen->font_set; - count = length = 0; + count = 0; if (!font_set->info && !font_set->font) { - length += strlen(font_set->font_data->name) + 1; count++; } @@ -499,7 +496,7 @@ set_missing_list( if (charset_list == NULL) return False; - charset_buf = Xmalloc(length); + charset_buf = strdup(font_set->font_data->name); if (charset_buf == NULL) { Xfree(charset_list); return False; @@ -510,7 +507,6 @@ set_missing_list( font_set = gen->font_set; if (!font_set->info && !font_set->font) { - strcpy(charset_buf, font_set->font_data->name); *charset_list++ = charset_buf; charset_buf += strlen(charset_buf) + 1; } @@ -1058,7 +1054,7 @@ init_om( char **required_list; XOrientation *orientation; char *bufptr; - int i, count, length = 0; + int i, count; count = XlcNumber(supported_charset_list); @@ -1078,14 +1074,12 @@ init_om( return False; } - length += strlen(data->font_data->name) + 1; - /* required charset list */ required_list = Xmalloc(sizeof(char *)); if (required_list == NULL) return False; - bufptr = Xmalloc(length); + bufptr = strdup(data->font_data->name); if (bufptr == NULL) { Xfree(required_list); return False; @@ -1096,7 +1090,6 @@ init_om( data = gen->data; - strcpy(bufptr, data->font_data->name); *required_list++ = bufptr; bufptr += strlen(bufptr) + 1; -- cgit v1.2.3 From d980be3c2c3c39bc4db64388b992d4535cbffcd6 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 10:00:22 -0800 Subject: XDefaultOMIF: additional code simplification Don't need to test for a case that we already returned for, don't need to store a count that will only ever be 1 if we didn't return, don't need to increment pointers to allow storing more than one item when we can only ever possibly do one. Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index f7b1b1d8c..e38739a0a 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -237,15 +237,10 @@ init_core_part( FontSet font_set; XFontStruct **font_struct_list; char **font_name_list, *font_name_buf; - int count; font_set = gen->font_set; - count = 0; - if (font_set->font_name != NULL) { - count++; - } - if (count == 0) + if (font_set->font_name == NULL) return False; font_struct_list = Xmalloc(sizeof(XFontStruct *)); @@ -264,18 +259,13 @@ init_core_part( oc->core.font_info.font_name_list = font_name_list; oc->core.font_info.font_struct_list = font_struct_list; - font_set = gen->font_set; - - if (font_set->font_name != NULL) { - font_set->id = 1; - if (font_set->font) - *font_struct_list++ = font_set->font; - else - *font_struct_list++ = font_set->info; - Xfree(font_set->font_name); - *font_name_list++ = font_set->font_name = font_name_buf; - font_name_buf += strlen(font_name_buf) + 1; - } + font_set->id = 1; + if (font_set->font) + *font_struct_list = font_set->font; + else + *font_struct_list = font_set->info; + Xfree(font_set->font_name); + *font_name_list = font_set->font_name = font_name_buf; set_fontset_extents(oc); @@ -480,16 +470,10 @@ set_missing_list( XOCGenericPart *gen = XOC_GENERIC(oc); FontSet font_set; char **charset_list, *charset_buf; - int count; font_set = gen->font_set; - count = 0; - - if (!font_set->info && !font_set->font) { - count++; - } - if (count == 0) + if (font_set->info == NULL || font_set->font == NULL) return True; charset_list = Xmalloc(sizeof(char *)); @@ -504,12 +488,8 @@ set_missing_list( oc->core.missing_list.charset_list = charset_list; - font_set = gen->font_set; + *charset_list = charset_buf; - if (!font_set->info && !font_set->font) { - *charset_list++ = charset_buf; - charset_buf += strlen(charset_buf) + 1; - } return True; } @@ -1090,8 +1070,7 @@ init_om( data = gen->data; - *required_list++ = bufptr; - bufptr += strlen(bufptr) + 1; + *required_list = bufptr; /* orientation list */ orientation = Xmalloc(sizeof(XOrientation)); -- cgit v1.2.3 From 2874fd14b84994762f41f1f13dac5c1b09bed095 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 19 Dec 2015 10:05:42 -0800 Subject: XDefaultOMIF: Remove comments referring to ancient Sun bug ids Signed-off-by: Alan Coopersmith Reviewed-by: Adam Jackson Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/XDefaultOMIF.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'nx-X11/lib/X11/XDefaultOMIF.c') diff --git a/nx-X11/lib/X11/XDefaultOMIF.c b/nx-X11/lib/X11/XDefaultOMIF.c index e38739a0a..e61344d31 100644 --- a/nx-X11/lib/X11/XDefaultOMIF.c +++ b/nx-X11/lib/X11/XDefaultOMIF.c @@ -369,11 +369,7 @@ parse_fontname( found_num++; goto found; } -/* -1266793 -Limit the length of the string copy to prevent stack corruption. - strcpy(buf, pattern); -*/ + strncpy(buf, pattern, BUFSIZ); buf[BUFSIZ-1] = '\0'; length = strlen(buf); @@ -425,11 +421,6 @@ Limit the length of the string copy to prevent stack corruption. for ( ; font_data_count-- > 0; font_data++) { if (append_charset) { -/* -1266793 -Limit the length of the string copy to prevent stack corruption. - strcpy(last, font_data->name); -*/ strncpy(last, font_data->name, BUFSIZ - length); buf[BUFSIZ-1] = '\0'; } @@ -1015,11 +1006,7 @@ add_data( static _Xconst char *supported_charset_list[] = { "ISO8859-1", -/* fix for bug4332979 */ "adobe-fontspecific", -/* fix for bug4237353: "JISX0201.1976-0" entry should be removed from - supported_charset_list because it is not a supported_charset for C locale - "JISX0201.1976-0", */ "SUNOLCURSOR-1", "SUNOLGLYPH-1" }; -- cgit v1.2.3