[PATCH:libXt 3/3] Convert ALLOCATE_LOCAL + sprintf to XtAsprintf

Cyril Brulebois kibi at debian.org
Mon Mar 7 10:57:24 PST 2011


Hi Alan,

Alan Coopersmith <alan.coopersmith at oracle.com> (12/01/2011):
> Now that we don't need to separately strlen the format string, put it
> directly into the function call to clear gcc warnings of:
> Initialize.c:397: warning: format not a string literal, argument types not checked
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
>  src/Initialize.c |   25 ++++++++++---------------
>  1 files changed, 10 insertions(+), 15 deletions(-)
> 
> diff --git a/src/Initialize.c b/src/Initialize.c
> index 2e70e39..e9543da 100644
> --- a/src/Initialize.c
> +++ b/src/Initialize.c
> @@ -380,7 +380,7 @@ static void CombineAppUserDefaults(
>      XrmDatabase *pdb)
>  {
>      char* filename;
> -    char* path;
> +    char* path = NULL;
>      Boolean deallocate = False;
>  
>      if (!(path = getenv("XUSERFILESEARCHPATH"))) {
> @@ -389,20 +389,14 @@ static void CombineAppUserDefaults(
>  	char homedir[PATH_MAX];
>  	GetRootDirName(homedir, PATH_MAX);
>  	if (!(old_path = getenv("XAPPLRESDIR"))) {
> -	    char *path_default = "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N";
> -	    if (!(path =
> -		  ALLOCATE_LOCAL(6*strlen(homedir) + strlen(path_default))))
> -		_XtAllocError(NULL);
> -	    sprintf( path, path_default,
> -		    homedir, homedir, homedir, homedir, homedir, homedir );
> +	    XtAsprintf(&path,
> +		       "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N",
> +		       homedir, homedir, homedir, homedir, homedir, homedir);
>  	} else {
> -	    char *path_default = "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N:%s/%%N";
> -	    if (!(path =
> -		  ALLOCATE_LOCAL( 6*strlen(old_path) + 2*strlen(homedir)
> -				 + strlen(path_default))))
> -		_XtAllocError(NULL);
> -	    sprintf(path, path_default, old_path, old_path, old_path, homedir,
> -		    old_path, old_path, old_path, homedir );
> +	    XtAsprintf(&path,
> +		       "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N:%s/%%N",
> +		       old_path, old_path, old_path, homedir,
> +		       old_path, old_path, old_path, homedir);
>  	}
>  	deallocate = True;
>  #endif
> @@ -414,7 +408,8 @@ static void CombineAppUserDefaults(
>  	XtFree(filename);
>      }
>  
> -    if (deallocate) DEALLOCATE_LOCAL(path);
> +    if (deallocate)
> +	XtFree(path);


I have yet to figure out why, but this breaks xdm when starting it
from init (but not through a /etc/init.d/xdm restart).

Reverting that commit makes xdm start from init, as well as replacing
XtAsprintf with asprintf (with a #define _GNU_SOURCE before including
<stdio.h>).

I also tried reinstating error checking (if XtAsprintf returns -1,
call _XtAllocError(NULL)), but that didn't change anything (I assumed
that “like asprintf” in the git log meant that return value would
match asprintf's).

Debian bug report:
  http://bugs.debian.org/617208

KiBi.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg-devel/attachments/20110307/32b77f90/attachment-0001.pgp>


More information about the xorg-devel mailing list