From f06e8a61d6ed8f3054878167bffee619f852aad9 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 30 Nov 2010 16:34:38 -0800 Subject: [PATCH 1/8] Move inclusion of panoramiX headers to top of render.c Fixes compiler error from Sun compilers due to _X_EXPORT declaration being included after the unlabeled version: "../Xext/panoramiXsrv.h", line 29: redeclaration must have the same or more restrictive linker scoping: XRT_PICTURE Signed-off-by: Alan Coopersmith Reviewed-by: Peter Hutterer --- render/render.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/render/render.c b/render/render.c index 85a43924a..0bbbae899 100644 --- a/render/render.c +++ b/render/render.c @@ -47,6 +47,11 @@ #include "xace.h" #include "protocol-versions.h" +#ifdef PANORAMIX +#include "panoramiX.h" +#include "panoramiXsrv.h" +#endif + #if HAVE_STDINT_H #include #elif !defined(UINT32_MAX) @@ -2651,9 +2656,6 @@ SProcRenderDispatch (ClientPtr client) } #ifdef PANORAMIX -#include "panoramiX.h" -#include "panoramiXsrv.h" - #define VERIFY_XIN_PICTURE(pPicture, pid, client, mode) {\ int rc = dixLookupResourceByType((pointer *)&(pPicture), pid,\ XRT_PICTURE, client, mode);\ From 2db6951763115a4a5dfac53d1a8f78ac33f91235 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 3 Dec 2010 16:32:01 -0800 Subject: [PATCH 2/8] Sun's copyrights now belong to Oracle Signed-off-by: Alan Coopersmith Reviewed-by: Mikhail Gusarov --- COPYING | 2 +- composite/compalloc.c | 2 +- composite/compext.c | 2 +- composite/compinit.c | 2 +- composite/compint.h | 2 +- composite/compoverlay.c | 2 +- composite/compwindow.c | 2 +- dix/Xserver-dtrace.h.in | 2 +- dix/Xserver.d | 2 +- dix/dispatch.c | 2 +- dix/events.c | 2 +- dix/resource.c | 2 +- fb/fbcmap_mi.c | 2 +- hw/xfree86/os-support/solaris/solaris-amd64.S | 2 +- hw/xfree86/os-support/solaris/solaris-ia32.S | 2 +- hw/xfree86/os-support/solaris/solaris-sparcv8plus.S | 2 +- hw/xfree86/os-support/solaris/sun_VTsw.c | 2 +- hw/xfree86/os-support/solaris/sun_agp.c | 2 +- hw/xfree86/os-support/solaris/sun_apm.c | 2 +- hw/xfree86/os-support/solaris/sun_bell.c | 2 +- hw/xfree86/os-support/solaris/sun_vid.c | 2 +- hw/xfree86/utils/cvt/Makefile.am | 2 +- hw/xfree86/utils/gtf/Makefile.am | 2 +- mi/micmap.c | 2 +- os/access.c | 2 +- xfixes/cursor.c | 2 +- xfixes/xfixes.c | 2 +- xfixes/xfixesint.h | 2 +- 28 files changed, 28 insertions(+), 28 deletions(-) diff --git a/COPYING b/COPYING index 3aad5faf6..bbf09ca76 100644 --- a/COPYING +++ b/COPYING @@ -15,11 +15,11 @@ Copyright © 2006 Nokia Corporation Copyright © 2006-2008 Peter Hutterer Copyright © 2006 Adam Jackson Copyright © 2009-2010 NVIDIA Corporation +Copyright © 1987, 2003-2006, 2008-2009 Oracle and/or its affiliates. Copyright © 1999 Keith Packard Copyright © 2007-2009 Red Hat, Inc. Copyright © 2005-2008 Daniel Stone Copyright © 2006-2009 Simon Thum -Copyright © 1987, 2003-2006, 2008-2009 Sun Microsystems, Inc. Copyright © 2006 Luc Verhaegen Permission is hereby granted, free of charge, to any person obtaining a diff --git a/composite/compalloc.c b/composite/compalloc.c index c86eb9b69..93571eef9 100644 --- a/composite/compalloc.c +++ b/composite/compalloc.c @@ -1,5 +1,5 @@ /* - * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2006, 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"), diff --git a/composite/compext.c b/composite/compext.c index 7fddbba92..fbd36b538 100644 --- a/composite/compext.c +++ b/composite/compext.c @@ -1,5 +1,5 @@ /* - * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2006, 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"), diff --git a/composite/compinit.c b/composite/compinit.c index 5db9f0282..159f7c2cc 100644 --- a/composite/compinit.c +++ b/composite/compinit.c @@ -1,5 +1,5 @@ /* - * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2006, 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"), diff --git a/composite/compint.h b/composite/compint.h index ae41c44fe..9ba5dd0ed 100644 --- a/composite/compint.h +++ b/composite/compint.h @@ -1,5 +1,5 @@ /* - * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2006, 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"), diff --git a/composite/compoverlay.c b/composite/compoverlay.c index 3bace79df..047f069ff 100644 --- a/composite/compoverlay.c +++ b/composite/compoverlay.c @@ -1,5 +1,5 @@ /* - * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2006, 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"), diff --git a/composite/compwindow.c b/composite/compwindow.c index 62283ee8a..bbd575651 100644 --- a/composite/compwindow.c +++ b/composite/compwindow.c @@ -1,5 +1,5 @@ /* - * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2006, 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"), diff --git a/dix/Xserver-dtrace.h.in b/dix/Xserver-dtrace.h.in index fce28362a..daf3faf1d 100644 --- a/dix/Xserver-dtrace.h.in +++ b/dix/Xserver-dtrace.h.in @@ -1,4 +1,4 @@ -/* Copyright 2006 Sun Microsystems, Inc. All rights reserved. +/* Copyright (c) 2006, 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"), diff --git a/dix/Xserver.d b/dix/Xserver.d index 4bc0b9a84..2ad337351 100644 --- a/dix/Xserver.d +++ b/dix/Xserver.d @@ -1,4 +1,4 @@ -/* Copyright 2005-2006 Sun Microsystems, Inc. All rights reserved. +/* Copyright (c) 2005-2006, 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"), diff --git a/dix/dispatch.c b/dix/dispatch.c index b66861f78..7b2132d3a 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -75,7 +75,7 @@ Equipment Corporation. ******************************************************************/ /* XSERVER_DTRACE additions: - * Copyright 2005-2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2005-2006, 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"), diff --git a/dix/events.c b/dix/events.c index e8cf8d417..ac0792360 100644 --- a/dix/events.c +++ b/dix/events.c @@ -75,7 +75,7 @@ Equipment Corporation. ******************************************************************/ /* - * Copyright © 2003-2005 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2003-2005, 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"), diff --git a/dix/resource.c b/dix/resource.c index a0fe719de..6bd240368 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -73,7 +73,7 @@ Equipment Corporation. ******************************************************************/ /* XSERVER_DTRACE additions: - * Copyright 2005-2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2005-2006, 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"), diff --git a/fb/fbcmap_mi.c b/fb/fbcmap_mi.c index d75a38fa2..227da3118 100644 --- a/fb/fbcmap_mi.c +++ b/fb/fbcmap_mi.c @@ -1,5 +1,5 @@ /* - * Copyright © 1987 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 1987, 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"), diff --git a/hw/xfree86/os-support/solaris/solaris-amd64.S b/hw/xfree86/os-support/solaris/solaris-amd64.S index 94ffa40e7..4cc0642dd 100644 --- a/hw/xfree86/os-support/solaris/solaris-amd64.S +++ b/hw/xfree86/os-support/solaris/solaris-amd64.S @@ -1,4 +1,4 @@ -/ Copyright 2005 Sun Microsystems, Inc. All rights reserved. +/ Copyright (c) 2005, 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"), diff --git a/hw/xfree86/os-support/solaris/solaris-ia32.S b/hw/xfree86/os-support/solaris/solaris-ia32.S index 4dadf7ffd..74d787d31 100644 --- a/hw/xfree86/os-support/solaris/solaris-ia32.S +++ b/hw/xfree86/os-support/solaris/solaris-ia32.S @@ -1,4 +1,4 @@ -/ Copyright 2004 Sun Microsystems, Inc. All rights reserved. +/ Copyright (c) 2004, 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"), diff --git a/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S b/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S index 0f6d694fd..0ecafb352 100644 --- a/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S +++ b/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S @@ -1,4 +1,4 @@ -/* Copyright 2004 Sun Microsystems, Inc. All rights reserved. +/* Copyright (c) 2004, 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"), diff --git a/hw/xfree86/os-support/solaris/sun_VTsw.c b/hw/xfree86/os-support/solaris/sun_VTsw.c index cff279e0c..e6f31879b 100644 --- a/hw/xfree86/os-support/solaris/sun_VTsw.c +++ b/hw/xfree86/os-support/solaris/sun_VTsw.c @@ -1,5 +1,5 @@ /* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2009, 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"), diff --git a/hw/xfree86/os-support/solaris/sun_agp.c b/hw/xfree86/os-support/solaris/sun_agp.c index dd4b1e2f9..a4517d666 100644 --- a/hw/xfree86/os-support/solaris/sun_agp.c +++ b/hw/xfree86/os-support/solaris/sun_agp.c @@ -6,7 +6,7 @@ * Copyright © 2000 VA Linux Systems, Inc. * Copyright © 2001 The XFree86 Project, Inc. */ -/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. +/* Copyright (c) 2005, 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"), diff --git a/hw/xfree86/os-support/solaris/sun_apm.c b/hw/xfree86/os-support/solaris/sun_apm.c index 23e14f17e..55081b6d1 100644 --- a/hw/xfree86/os-support/solaris/sun_apm.c +++ b/hw/xfree86/os-support/solaris/sun_apm.c @@ -27,7 +27,7 @@ * XFree86 Project. */ -/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. +/* Copyright (c) 2005, 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"), diff --git a/hw/xfree86/os-support/solaris/sun_bell.c b/hw/xfree86/os-support/solaris/sun_bell.c index bab391372..b59835e53 100644 --- a/hw/xfree86/os-support/solaris/sun_bell.c +++ b/hw/xfree86/os-support/solaris/sun_bell.c @@ -1,4 +1,4 @@ -/* Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved. +/* Copyright (c) 2004-2005, 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"), diff --git a/hw/xfree86/os-support/solaris/sun_vid.c b/hw/xfree86/os-support/solaris/sun_vid.c index 94979736d..f99bac517 100644 --- a/hw/xfree86/os-support/solaris/sun_vid.c +++ b/hw/xfree86/os-support/solaris/sun_vid.c @@ -22,7 +22,7 @@ * OF THIS SOFTWARE. * */ -/* Copyright 2008 Sun Microsystems, Inc. All rights reserved. +/* Copyright (c) 2008, 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"), diff --git a/hw/xfree86/utils/cvt/Makefile.am b/hw/xfree86/utils/cvt/Makefile.am index 6b99cbd5f..065868257 100644 --- a/hw/xfree86/utils/cvt/Makefile.am +++ b/hw/xfree86/utils/cvt/Makefile.am @@ -1,4 +1,4 @@ -# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Copyright (c) 2005, 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"), diff --git a/hw/xfree86/utils/gtf/Makefile.am b/hw/xfree86/utils/gtf/Makefile.am index d1a6d611c..ea1c5fb8c 100644 --- a/hw/xfree86/utils/gtf/Makefile.am +++ b/hw/xfree86/utils/gtf/Makefile.am @@ -1,4 +1,4 @@ -# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Copyright (c) 2005, 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"), diff --git a/mi/micmap.c b/mi/micmap.c index 8d76f4df7..41e03006e 100644 --- a/mi/micmap.c +++ b/mi/micmap.c @@ -1,5 +1,5 @@ /* - * Copyright © 1987 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 1987, 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"), diff --git a/os/access.c b/os/access.c index d9de2649d..a532db661 100644 --- a/os/access.c +++ b/os/access.c @@ -54,7 +54,7 @@ SOFTWARE. ******************************************************************/ /* - * Copyright © 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2004, 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"), diff --git a/xfixes/cursor.c b/xfixes/cursor.c index 41ba0fbac..54e5d755e 100644 --- a/xfixes/cursor.c +++ b/xfixes/cursor.c @@ -1,5 +1,5 @@ /* - * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2006, 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"), diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c index 5dbfbec1b..e8c7bf161 100644 --- a/xfixes/xfixes.c +++ b/xfixes/xfixes.c @@ -1,5 +1,5 @@ /* - * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2006, 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"), diff --git a/xfixes/xfixesint.h b/xfixes/xfixesint.h index 9e50993c3..d00536968 100644 --- a/xfixes/xfixesint.h +++ b/xfixes/xfixesint.h @@ -1,5 +1,5 @@ /* - * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2006, 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"), From c95c1d338fdb62dbe3dba934b97324fa778b7fce Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 27 Nov 2010 18:43:12 -0800 Subject: [PATCH 3/8] Add asprintf() implementation for platforms without it Provides a portable implementation of this common allocating sprintf() API found in many, but not yet all, of the platforms we support. If the platform provides vasprintf() we simply wrap it, otherwise we implement it - either way callers can use it regardless of platform. Since not all platforms guarantee to NULL out the return pointer on failure, we don't either, and require callers to check the return value for -1. The old Xprintf() API is deprecated, but left for compatibility for now. The new API is added in a new header so that it can be used in parts of the server such as hw/xfree86/parser that don't include all the server headers. Signed-off-by: Alan Coopersmith Reviewed-by: Mikhail Gusarov --- COPYING | 2 +- configure.ac | 2 +- hw/xfree86/loader/sdksyms.sh | 1 + include/Makefile.am | 1 + include/Xprintf.h | 69 ++++++++++++++ include/dix-config.h.in | 3 + include/os.h | 12 ++- os/xprintf.c | 170 ++++++++++++++++++++++++++++++----- 8 files changed, 230 insertions(+), 30 deletions(-) create mode 100644 include/Xprintf.h diff --git a/COPYING b/COPYING index bbf09ca76..cd9e80a48 100644 --- a/COPYING +++ b/COPYING @@ -15,7 +15,7 @@ Copyright © 2006 Nokia Corporation Copyright © 2006-2008 Peter Hutterer Copyright © 2006 Adam Jackson Copyright © 2009-2010 NVIDIA Corporation -Copyright © 1987, 2003-2006, 2008-2009 Oracle and/or its affiliates. +Copyright © 1987, 2003-2006, 2008-2010 Oracle and/or its affiliates. Copyright © 1999 Keith Packard Copyright © 2007-2009 Red Hat, Inc. Copyright © 2005-2008 Daniel Stone diff --git a/configure.ac b/configure.ac index b56d3e8a2..d2318dafd 100644 --- a/configure.ac +++ b/configure.ac @@ -203,7 +203,7 @@ dnl Checks for library functions. AC_FUNC_VPRINTF AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr \ strtol getopt getopt_long vsnprintf walkcontext backtrace \ - getisax getzoneid shmctl64 strcasestr ffs]) + getisax getzoneid shmctl64 strcasestr ffs vasprintf]) AC_FUNC_ALLOCA dnl Old HAS_* names used in os/*.c. AC_CHECK_FUNC([getdtablesize], diff --git a/hw/xfree86/loader/sdksyms.sh b/hw/xfree86/loader/sdksyms.sh index 4ac3c818c..356d490fa 100755 --- a/hw/xfree86/loader/sdksyms.sh +++ b/hw/xfree86/loader/sdksyms.sh @@ -253,6 +253,7 @@ cat > sdksyms.c << EOF /* include/Makefile.am */ #include "XIstubs.h" +#include "Xprintf.h" #include "closestr.h" #include "closure.h" #include "colormap.h" diff --git a/include/Makefile.am b/include/Makefile.am index 966d21525..42f008269 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,6 +1,7 @@ if XORG sdk_HEADERS = \ XIstubs.h \ + Xprintf.h \ callback.h \ closestr.h \ closure.h \ diff --git a/include/Xprintf.h b/include/Xprintf.h new file mode 100644 index 000000000..5177122c9 --- /dev/null +++ b/include/Xprintf.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010, 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef XPRINTF_H +#define XPRINTF_H + +#include +#include +#include + +#ifndef _X_RESTRICT_KYWD +# if defined(restrict) /* assume autoconf set it correctly */ || \ + (defined(__STDC__) && (__STDC_VERSION__ - 0 >= 199901L)) /* C99 */ +# define _X_RESTRICT_KYWD restrict +# elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */ +# define _X_RESTRICT_KYWD __restrict__ +# else +# define _X_RESTRICT_KYWD +# endif +#endif + +/* + * These functions provide a portable implementation of the common (but not + * yet universal) asprintf & vasprintf routines to allocate a buffer big + * enough to sprintf the arguments to. The XNF variants terminate the server + * if the allocation fails. + * The buffer allocated is returned in the pointer provided in the first + * argument. The return value is the size of the allocated buffer, or -1 + * on failure. + */ +extern _X_EXPORT int Xasprintf (char **ret, + const char * _X_RESTRICT_KYWD fmt, + ...) _X_ATTRIBUTE_PRINTF(2,3); +extern _X_EXPORT int Xvasprintf (char **ret, + const char * _X_RESTRICT_KYWD fmt, + va_list va) _X_ATTRIBUTE_PRINTF(2,0); +extern _X_EXPORT int XNFasprintf (char **ret, + const char * _X_RESTRICT_KYWD fmt, + ...) _X_ATTRIBUTE_PRINTF(2,3); +extern _X_EXPORT int XNFvasprintf (char **ret, + const char * _X_RESTRICT_KYWD fmt, + va_list va) _X_ATTRIBUTE_PRINTF(2,0); + +#if !defined(HAVE_ASPRINTF) && !defined(HAVE_VASPRINTF) +# define asprintf Xasprintf +# define vasprintf Xvasprintf +#endif + +#endif /* XPRINTF_H */ diff --git a/include/dix-config.h.in b/include/dix-config.h.in index 6a332642b..5622766b8 100644 --- a/include/dix-config.h.in +++ b/include/dix-config.h.in @@ -243,6 +243,9 @@ /* Define to 1 if you have the `vprintf' function. */ #undef HAVE_VPRINTF +/* Define to 1 if you have the `vasprintf' function. */ +#undef HAVE_VASPRINTF + /* Support IPv6 for TCP connections */ #undef IPv6 diff --git a/include/os.h b/include/os.h index 566514d4a..88f23aeed 100644 --- a/include/os.h +++ b/include/os.h @@ -263,10 +263,14 @@ extern _X_EXPORT char *Xstrdup(const char *s); */ extern _X_EXPORT char *XNFstrdup(const char *s); -extern _X_EXPORT char *Xprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); -extern _X_EXPORT char *Xvprintf(const char *fmt, va_list va); -extern _X_EXPORT char *XNFprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); -extern _X_EXPORT char *XNFvprintf(const char *fmt, va_list va); +/* Include new X*asprintf API */ +#include "Xprintf.h" + +/* Older api deprecated in favor of the asprintf versions */ +extern _X_EXPORT char *Xprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2) _X_DEPRECATED; +extern _X_EXPORT char *Xvprintf(const char *fmt, va_list va)_X_ATTRIBUTE_PRINTF(1,0) _X_DEPRECATED; +extern _X_EXPORT char *XNFprintf(const char *fmt, ...) _X_ATTRIBUTE_PRINTF(1,2) _X_DEPRECATED; +extern _X_EXPORT char *XNFvprintf(const char *fmt, va_list va)_X_ATTRIBUTE_PRINTF(1,0) _X_DEPRECATED; typedef void (*OsSigHandlerPtr)(int /* sig */); typedef int (*OsSigWrapperPtr)(int /* sig */); diff --git a/os/xprintf.c b/os/xprintf.c index 71a4424f7..0a8bd0687 100644 --- a/os/xprintf.c +++ b/os/xprintf.c @@ -1,6 +1,13 @@ -/* - * printf routines which xalloc their buffer - */ +/** + * @file + * + * @section DESCRIPTION + * + * These functions provide a portable implementation of the common (but not + * yet universal) asprintf & vasprintf routines to allocate a buffer big + * enough to sprintf the arguments to. The XNF variants terminate the server + * if the allocation fails. + */ /* * Copyright (c) 2004 Alexander Gottwald * @@ -26,6 +33,29 @@ * holders shall not be used in advertising or otherwise to promote the sale, * use or other dealings in this Software without prior written authorization. */ +/* + * Copyright (c) 2010, 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + #ifdef HAVE_DIX_CONFIG_H #include #endif @@ -35,6 +65,13 @@ #include #include +#ifdef asprintf +# undef asprintf +#endif +#ifdef vasprintf +# undef vasprintf +#endif + #ifndef va_copy # ifdef __va_copy # define va_copy __va_copy @@ -42,11 +79,23 @@ # error "no working va_copy was found" # endif #endif - -char * -Xvprintf(const char *format, va_list va) + +/** + * Varargs sprintf that allocates a string buffer the right size for + * the pattern & data provided and prints the requested data to it. + * + * @param ret Pointer to which the newly allocated buffer is written + * (contents undefined on error) + * @param format printf style format string + * @param va variable argument list + * @return size of allocated buffer, or -1 on error. + */ +int +Xvasprintf(char **ret, const char * _X_RESTRICT_KYWD format, va_list va) { - char *ret; +#ifdef HAVE_VASPRINTF + return vasprintf(ret, format, va); +#else int size; va_list va2; @@ -54,12 +103,94 @@ Xvprintf(const char *format, va_list va) size = vsnprintf(NULL, 0, format, va2); va_end(va2); - ret = (char *)malloc(size + 1); - if (ret == NULL) - return NULL; + *ret = malloc(size + 1); + if (*ret == NULL) + return -1; - vsnprintf(ret, size + 1, format, va); + vsnprintf(*ret, size + 1, format, va); ret[size] = 0; + return size; +#endif +} + +#ifndef HAVE_VASPRINTF +# define vasprintf Xvasprintf +#endif + +/** + * sprintf that allocates a string buffer the right size for + * the pattern & data provided and prints the requested data to it. + * + * @param ret Pointer to which the newly allocated buffer is written + * (contents undefined on error) + * @param format printf style format string + * @param ... arguments for specified format + * @return size of allocated buffer, or -1 on error. + */ +int +Xasprintf(char ** ret, const char * _X_RESTRICT_KYWD format, ...) +{ + int size; + va_list va; + va_start(va, format); + size = vasprintf(ret, format, va); + va_end(va); + return size; +} + +/** + * Varargs sprintf that allocates a string buffer the right size for + * the pattern & data provided and prints the requested data to it. + * On failure, issues a FatalError message and aborts the server. + * + * @param ret Pointer to which the newly allocated buffer is written + * (contents undefined on error) + * @param format printf style format string + * @param va variable argument list + * @return size of allocated buffer + */ +int +XNFvasprintf(char **ret, const char * _X_RESTRICT_KYWD format, va_list va) +{ + int size = vasprintf(ret, format, va); + if ((size == -1) || (*ret == NULL)) { + Error("XNFvasprintf"); + FatalError("XNFvasprintf failed"); + } + return size; +} + +/** + * sprintf that allocates a string buffer the right size for + * the pattern & data provided and prints the requested data to it. + * On failure, issues a FatalError message and aborts the server. + * + * @param ret Pointer to which the newly allocated buffer is written + * (contents undefined on error) + * @param format printf style format string + * @param ... arguments for specified format + * @return size of allocated buffer + */ +int +XNFasprintf(char ** ret, const char * _X_RESTRICT_KYWD format, ...) +{ + int size; + va_list va; + va_start(va, format); + size = XNFvasprintf(ret, format, va); + va_end(va); + return size; +} + +/* Old api, now deprecated, may be removed in the future */ +char * +Xvprintf(const char *format, va_list va) +{ + char *ret; + + if (vasprintf(&ret, format, va) == -1) + ret = NULL; + return ret; } @@ -68,7 +199,8 @@ char *Xprintf(const char *format, ...) char *ret; va_list va; va_start(va, format); - ret = Xvprintf(format, va); + if (vasprintf(&ret, format, va) == -1) + ret = NULL; va_end(va); return ret; } @@ -77,19 +209,9 @@ char * XNFvprintf(const char *format, va_list va) { char *ret; - int size; - va_list va2; - va_copy(va2, va); - size = vsnprintf(NULL, 0, format, va2); - va_end(va2); + XNFvasprintf(&ret, format, va); - ret = (char *)xnfalloc(size + 1); - if (ret == NULL) - return NULL; - - vsnprintf(ret, size + 1, format, va); - ret[size] = 0; return ret; } @@ -98,7 +220,7 @@ char *XNFprintf(const char *format, ...) char *ret; va_list va; va_start(va, format); - ret = XNFvprintf(format, va); + XNFvasprintf(&ret, format, va); va_end(va); return ret; } From 03e8bfa1d122f7dea905d48c93cfd54afd991dfd Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 27 Nov 2010 20:09:04 -0800 Subject: [PATCH 4/8] Convert existing Xprintf style calls to asprintf style Signed-off-by: Alan Coopersmith Reviewed-by: Jeremy Huddleston Reviewed-by: Mikhail Gusarov --- config/hal.c | 4 ++- config/udev.c | 14 +++++----- dix/dixfonts.c | 4 ++- hw/xfree86/common/xf86AutoConfig.c | 4 +-- hw/xfree86/common/xf86Config.c | 9 +++---- hw/xfree86/common/xf86Helper.c | 10 ++++--- hw/xfree86/modes/xf86Modes.c | 4 +-- hw/xwin/win.h | 7 ++--- hw/xwin/windialogs.c | 5 ++-- hw/xwin/winerror.c | 24 ++++++++++------- xkb/ddxList.c | 43 +++++++++++++++++++----------- xkb/ddxLoad.c | 19 +++++++------ 12 files changed, 88 insertions(+), 59 deletions(-) diff --git a/config/hal.c b/config/hal.c index 6e2850cf7..5e35911fd 100644 --- a/config/hal.c +++ b/config/hal.c @@ -200,7 +200,9 @@ device_added(LibHalContext *hal_ctx, const char *udi) "config/hal: getting usb.product_id on %s " "returned %04x\n", parent, usb_product); if (usb_vendor && usb_product) - attrs.usb_id = Xprintf("%04x:%04x", usb_vendor, usb_product); + if (asprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_product) + == -1) + attrs.usb_id = NULL; free(parent); } diff --git a/config/udev.c b/config/udev.c index 31f4f80cc..496bfbf11 100644 --- a/config/udev.c +++ b/config/udev.c @@ -108,8 +108,10 @@ device_added(struct udev_device *udev_device) /* construct USB ID in lowercase hex - "0000:ffff" */ if (product && sscanf(product, "%*x/%4x/%4x/%*x", &usb_vendor, &usb_model) == 2) { - attrs.usb_id = Xprintf("%04x:%04x", usb_vendor, usb_model); - if (attrs.usb_id) + if (asprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_model) + == -1) + attrs.usb_id = NULL; + else LOG_PROPERTY(path, "PRODUCT", product); } } @@ -127,9 +129,10 @@ device_added(struct udev_device *udev_device) LOG_PROPERTY(path, "ID_INPUT.tags", tags_prop); attrs.tags = xstrtokenize(tags_prop, ","); - config_info = Xprintf("udev:%s", syspath); - if (!config_info) + if (asprintf(&config_info, "udev:%s", syspath) == -1) { + config_info = NULL; goto unwind; + } if (device_is_duplicate(config_info)) { LogMessage(X_WARNING, "config/udev: device %s already added. " @@ -217,8 +220,7 @@ device_removed(struct udev_device *device) char *value; const char *syspath = udev_device_get_syspath(device); - value = Xprintf("udev:%s", syspath); - if (!value) + if (asprintf(&value, "udev:%s", syspath) == -1) return; remove_devices("udev", value); diff --git a/dix/dixfonts.c b/dix/dixfonts.c index ccb462794..bd1ad3075 100644 --- a/dix/dixfonts.c +++ b/dix/dixfonts.c @@ -1817,7 +1817,9 @@ SetDefaultFontPath(char *path) start = end; } if (!start) { - temp_path = Xprintf("%s%sbuilt-ins", path, *path ? "," : ""); + if (asprintf(&temp_path, "%s%sbuilt-ins", path, *path ? "," : "") + == -1) + temp_path = NULL; } else { temp_path = strdup(path); } diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c index 3cd5ef6ff..eb61f879a 100644 --- a/hw/xfree86/common/xf86AutoConfig.c +++ b/hw/xfree86/common/xf86AutoConfig.c @@ -297,8 +297,8 @@ copyScreen(confScreenPtr oscreen, GDevPtr odev, int i, char *driver) } memcpy(cptr, odev, sizeof(GDevRec)); - cptr->identifier = Xprintf("Autoconfigured Video Device %s", driver); - if (!cptr->identifier) { + if (asprintf(&cptr->identifier, "Autoconfigured Video Device %s", driver) + == -1) { free(cptr); free(nscreen); return FALSE; diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index ae9592e24..5f3b8e8be 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -585,12 +585,11 @@ configFiles(XF86ConfFilesPtr fileconf) else if (fileconf && fileconf->file_fontpath) { pathFrom = X_CONFIG; if (xf86Info.useDefaultFontPath) { - defaultFontPath = Xprintf("%s%s%s", - fileconf->file_fontpath, - *temp_path ? "," : "", temp_path); - if (defaultFontPath != NULL) { + if (asprintf(&defaultFontPath, "%s%s%s", fileconf->file_fontpath, + *temp_path ? "," : "", temp_path) == -1) + defaultFontPath = NULL; + else must_copy = FALSE; - } } else defaultFontPath = fileconf->file_fontpath; diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index 01f9864bb..ce144544b 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -1193,9 +1193,13 @@ xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, const char *forma { char *msg; - msg = Xprintf("%s: %s: %s", dev->drv->driverName, dev->name, format); - LogVMessageVerb(type, verb, msg, args); - free(msg); + if (asprintf(&msg, "%s: %s: %s", dev->drv->driverName, dev->name, format) + == -1) { + LogVMessageVerb(type, verb, "%s", args); + } else { + LogVMessageVerb(type, verb, msg, args); + free(msg); + } } /* Print input driver message, with verbose level specified directly */ diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c index 51eb4c952..75584cf87 100644 --- a/hw/xfree86/modes/xf86Modes.c +++ b/hw/xfree86/modes/xf86Modes.c @@ -132,8 +132,8 @@ xf86SetModeDefaultName(DisplayModePtr mode) free(mode->name); - mode->name = XNFprintf("%dx%d%s", mode->HDisplay, mode->VDisplay, - interlaced ? "i" : ""); + XNFasprintf(&mode->name, "%dx%d%s", mode->HDisplay, mode->VDisplay, + interlaced ? "i" : ""); } /* diff --git a/hw/xwin/win.h b/hw/xwin/win.h index f22a2d576..44307813c 100644 --- a/hw/xwin/win.h +++ b/hw/xwin/win.h @@ -221,9 +221,10 @@ if (fDebugProcMsg) \ { \ char *pszTemp; \ int iLength; \ - pszTemp = Xprintf (str, ##__VA_ARGS__); \ - MessageBox (NULL, pszTemp, szFunctionName, MB_OK); \ - free(pszTemp); \ + if (asprintf (&pszTemp, str, ##__VA_ARGS__) != -1) { \ + MessageBox (NULL, pszTemp, szFunctionName, MB_OK); \ + free (pszTemp); \ + } \ } #else #define DEBUG_MSG(str,...) diff --git a/hw/xwin/windialogs.c b/hw/xwin/windialogs.c index 22d8cd7f7..679b3fab5 100644 --- a/hw/xwin/windialogs.c +++ b/hw/xwin/windialogs.c @@ -341,11 +341,10 @@ winExitDlgProc (HWND hDialog, UINT message, winInitDialog (hDialog); /* Format the connected clients string */ - pszConnectedClients = Xprintf (CONNECTED_CLIENTS_FORMAT, + if (asprintf (&pszConnectedClients, CONNECTED_CLIENTS_FORMAT, (s_pScreenPriv->iConnectedClients == 1) ? "is" : "are", s_pScreenPriv->iConnectedClients, - (s_pScreenPriv->iConnectedClients == 1) ? "" : "s"); - if (!pszConnectedClients) + (s_pScreenPriv->iConnectedClients == 1) ? "" : "s") == -1) return TRUE; diff --git a/hw/xwin/winerror.c b/hw/xwin/winerror.c index aadfd2858..5e32d090d 100644 --- a/hw/xwin/winerror.c +++ b/hw/xwin/winerror.c @@ -101,12 +101,15 @@ winMessageBoxF (const char *pszError, UINT uType, ...) char * pszErrorF = NULL; char * pszMsgBox = NULL; va_list args; + int size; va_start(args, uType); - pszErrorF = Xvprintf(pszError, args); + size = vasprintf (&pszErrorF, pszError, args); va_end(args); - if (!pszErrorF) + if (size == -1) { + pszErrorF = NULL; goto winMessageBoxF_Cleanup; + } #define MESSAGEBOXF \ "%s\n" \ @@ -117,15 +120,18 @@ winMessageBoxF (const char *pszError, UINT uType, ...) "XWin was started with the following command-line:\n\n" \ "%s\n" - pszMsgBox = Xprintf (MESSAGEBOXF, - pszErrorF, XVENDORNAME, - XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, XORG_VERSION_SNAP, XORG_VERSION_CURRENT, - BUILDERADDR, - BUILDERSTRING, - g_pszCommandLine); + size = asprintf (&pszMsgBox, MESSAGEBOXF, + pszErrorF, XVENDORNAME, + XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, + XORG_VERSION_SNAP, XORG_VERSION_CURRENT, + BUILDERADDR, + BUILDERSTRING, + g_pszCommandLine); - if (!pszMsgBox) + if (size == -1) { + pszMsgBox = NULL; goto winMessageBoxF_Cleanup; + } /* Display the message box string */ MessageBox (NULL, diff --git a/xkb/ddxList.c b/xkb/ddxList.c index c1ada5c6d..9623cb6aa 100644 --- a/xkb/ddxList.c +++ b/xkb/ddxList.c @@ -156,34 +156,45 @@ char tmpname[PATH_MAX]; #endif if (XkbBaseDirectory!=NULL) { if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) { - buf = Xprintf("%s/%s.dir",XkbBaseDirectory,componentDirs[what]); - in= fopen(buf,"r"); + if (asprintf(&buf, "%s/%s.dir", XkbBaseDirectory, + componentDirs[what]) == -1) + buf = NULL; + else + in = fopen(buf,"r"); } if (!in) { haveDir= FALSE; free(buf); - buf = Xprintf( - "'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg, - XkbBinDirectory,XkbBaseDirectory,componentDirs[what],(long) - ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)), - file W32_tmpfile - ); + if (asprintf + (&buf, + "'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg, + XkbBinDirectory, XkbBaseDirectory, componentDirs[what], + (long) ((xkbDebugFlags < 2) ? 1 : + ((xkbDebugFlags > 10) ? 10 : xkbDebugFlags)), + file W32_tmpfile + ) == -1) + buf = NULL; } } else { if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) { - buf = Xprintf("%s.dir",componentDirs[what]); - in= fopen(buf,"r"); + if (asprintf(&buf, "%s.dir", componentDirs[what]) == -1) + buf = NULL; + else + in = fopen(buf,"r"); } if (!in) { haveDir= FALSE; free(buf); - buf = Xprintf( - "xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg, - componentDirs[what],(long) - ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)), - file W32_tmpfile - ); + if (asprintf + (&buf, + "xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg, + componentDirs[what], + (long) ((xkbDebugFlags < 2) ? 1 : + ((xkbDebugFlags > 10) ? 10 : xkbDebugFlags)), + file W32_tmpfile + ) == -1) + buf = NULL; } } status= Success; diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c index cfc6198fd..e6904a501 100644 --- a/xkb/ddxLoad.c +++ b/xkb/ddxLoad.c @@ -210,7 +210,8 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, #endif if (XkbBaseDirectory != NULL) { - xkbbasedirflag = Xprintf("\"-R%s\"", XkbBaseDirectory); + if (asprintf(&xkbbasedirflag, "\"-R%s\"", XkbBaseDirectory) == -1) + xkbbasedirflag = NULL; } if (XkbBinDirectory != NULL) { @@ -225,14 +226,16 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, } } - buf = Xprintf("\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" " + if (asprintf(&buf, + "\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" " "-em1 %s -emp %s -eml %s \"%s%s.xkm\"", - xkbbindir, xkbbindirsep, - ( (xkbDebugFlags < 2) ? 1 : - ((xkbDebugFlags > 10) ? 10 : (int)xkbDebugFlags) ), - xkbbasedirflag ? xkbbasedirflag : "", xkmfile, - PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1, - xkm_output_dir, keymap); + xkbbindir, xkbbindirsep, + ((xkbDebugFlags < 2) ? 1 : + ((xkbDebugFlags > 10) ? 10 : (int) xkbDebugFlags)), + xkbbasedirflag ? xkbbasedirflag : "", xkmfile, + PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1, + xkm_output_dir, keymap) == -1) + buf = NULL; free(xkbbasedirflag); From 2416255f7e3fd9190a9e01bda57c992932de4bd9 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 27 Nov 2010 22:36:44 -0800 Subject: [PATCH 5/8] Convert hw/xfree86/parser code to use asprintf() calls Requires linking xprintf.c into libxf86config for those who build it. Signed-off-by: Alan Coopersmith Reviewed-by: Mikhail Gusarov --- hw/xfree86/parser/Flags.c | 13 ++++--------- hw/xfree86/parser/Makefile.am | 1 + hw/xfree86/parser/Pointer.c | 16 ++++++---------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c index a9149c243..7a0794bb0 100644 --- a/hw/xfree86/parser/Flags.c +++ b/hw/xfree86/parser/Flags.c @@ -61,8 +61,8 @@ #include "xf86Parser.h" #include "xf86tokens.h" #include "Configint.h" -#include #include +#include "Xprintf.h" extern LexRec val; @@ -143,9 +143,8 @@ xf86parseFlagsSection (void) } else { if (tokentype != NUMBER) Error (NUMBER_MSG, tmp); - valstr = malloc(16); - if (valstr) - sprintf(valstr, "%d", val.num); + if (asprintf(&valstr, "%d", val.num) == -1) + valstr = NULL; } } ptr->flg_option_lst = xf86addNewOption @@ -426,13 +425,9 @@ char * xf86uLongToString(unsigned long i) { char *s; - int l; - l = ceil(log10((double)i) + 2.5); - s = malloc(l); - if (!s) + if (asprintf(&s, "%lu", i) == -1) return NULL; - sprintf(s, "%lu", i); return s; } diff --git a/hw/xfree86/parser/Makefile.am b/hw/xfree86/parser/Makefile.am index caf7079d4..a5adc01ee 100644 --- a/hw/xfree86/parser/Makefile.am +++ b/hw/xfree86/parser/Makefile.am @@ -31,6 +31,7 @@ libxf86config_internal_la_SOURCES = \ $(INTERNAL_SOURCES) libxf86config_a_SOURCES = \ + $(TOP_SRCDIR)/os/xprintf.c \ $(INTERNAL_SOURCES) libxf86config_a_CFLAGS = $(AM_CFLAGS) diff --git a/hw/xfree86/parser/Pointer.c b/hw/xfree86/parser/Pointer.c index 56a26ba74..65397cd81 100644 --- a/hw/xfree86/parser/Pointer.c +++ b/hw/xfree86/parser/Pointer.c @@ -62,6 +62,7 @@ #include "xf86Parser.h" #include "xf86tokens.h" #include "Configint.h" +#include "Xprintf.h" extern LexRec val; @@ -99,8 +100,8 @@ static xf86ConfigSymTabRec ZMapTab[] = XF86ConfInputPtr xf86parsePointerSection (void) { - char *s, *s1, *s2; - int l; + char *s; + unsigned long val1; int token; parsePrologue (XF86ConfInputPtr, XF86ConfInputRec) @@ -184,17 +185,12 @@ xf86parsePointerSection (void) case NUMBER: if (val.num < 0) Error (ZAXISMAPPING_MSG, NULL); - s1 = xf86uLongToString(val.num); + val1 = val.num; if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) { - free(s1); Error (ZAXISMAPPING_MSG, NULL); } - s2 = xf86uLongToString(val.num); - l = strlen(s1) + 1 + strlen(s2) + 1; - s = malloc(l); - sprintf(s, "%s %s", s1, s2); - free(s1); - free(s2); + if (asprintf(&s, "%ul %ul", val1, val.num) == -1) + s = NULL; break; case XAXIS: s = strdup("x"); From 3a9bb93dd178084f4ff1abcea331ca5a62f88ce6 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 27 Nov 2010 22:38:27 -0800 Subject: [PATCH 6/8] Convert alloc+sprintf pairs into asprintf() & XNFasprintf() calls Signed-off-by: Alan Coopersmith Reviewed-by: Mikhail Gusarov --- config/hal.c | 9 +++------ hw/xfree86/common/xf86Configure.c | 33 +++++++++++-------------------- hw/xfree86/common/xf86Helper.c | 5 +---- hw/xfree86/common/xf86Init.c | 3 +-- hw/xfree86/common/xf86ShowOpts.c | 3 +++ hw/xfree86/common/xf86pciBus.c | 4 ++-- hw/xfree86/common/xf86sbusBus.c | 6 ++---- hw/xfree86/dri/dri.c | 7 ++----- hw/xfree86/loader/loadmod.c | 12 +++++------ hw/xfree86/vbe/vbeModes.c | 4 ++-- os/log.c | 12 +++-------- 11 files changed, 36 insertions(+), 62 deletions(-) diff --git a/config/hal.c b/config/hal.c index 5e35911fd..0b848a0f7 100644 --- a/config/hal.c +++ b/config/hal.c @@ -63,10 +63,8 @@ device_removed(LibHalContext *ctx, const char *udi) { char *value; - value = malloc(strlen(udi) + 5); /* "hal:" + NULL */ - if (!value) + if (asprintf (&value, "hal:%s", udi) == -1) return; - sprintf(value, "hal:%s", udi); remove_devices("hal", value); @@ -228,12 +226,11 @@ device_added(LibHalContext *hal_ctx, const char *udi) add_option(&options, "driver", driver); add_option(&options, "name", name); - config_info = malloc(strlen(udi) + 5); /* "hal:" and NULL */ - if (!config_info) { + if (asprintf (&config_info, "hal:%s", udi) == -1) { + config_info = NULL; LogMessage(X_ERROR, "config/hal: couldn't allocate name\n"); goto unwind; } - sprintf(config_info, "hal:%s", udi); /* Check for duplicate devices */ if (device_is_duplicate(config_info)) diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 7235c6175..b89f70161 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -205,12 +205,9 @@ configureScreenSection (int screennum) int depths[] = { 1, 4, 8, 15, 16, 24/*, 32*/ }; parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec) - ptr->scrn_identifier = malloc(18); - sprintf(ptr->scrn_identifier, "Screen%d", screennum); - ptr->scrn_monitor_str = malloc(19); - sprintf(ptr->scrn_monitor_str, "Monitor%d", screennum); - ptr->scrn_device_str = malloc(16); - sprintf(ptr->scrn_device_str, "Card%d", screennum); + XNFasprintf(&ptr->scrn_identifier, "Screen%d", screennum); + XNFasprintf(&ptr->scrn_monitor_str, "Monitor%d", screennum); + XNFasprintf(&ptr->scrn_device_str, "Card%d", screennum); for (i=0; idev_identifier = strdup(identifier); + if (asprintf(&ptr->dev_identifier, "Card%d", screennum) == -1) + ptr->dev_identifier = NULL; ptr->dev_chipset = DevToConfig[screennum].GDev.chipset; ptr->dev_busid = DevToConfig[screennum].GDev.busID; ptr->dev_driver = DevToConfig[screennum].GDev.driver; @@ -306,10 +302,8 @@ configureDeviceSection (int screennum) int len = strlen(ptr->dev_comment) + strlen(prefix) + strlen(middle) + strlen(suffix) + 1; - optname = malloc(strlen(p->name) + 2 + 1); - if (!optname) + if (asprintf(&optname, "\"%s\"", p->name) == -1) break; - sprintf(optname, "\"%s\"", p->name); len += max(20, strlen(optname)); len += strlen(opttype); @@ -370,16 +364,14 @@ configureLayoutSection (void) aptr->adj_x = 0; aptr->adj_y = 0; aptr->adj_scrnum = scrnum; - aptr->adj_screen_str = xnfalloc(18); - sprintf(aptr->adj_screen_str, "Screen%d", scrnum); + XNFasprintf(&aptr->adj_screen_str, "Screen%d", scrnum); if (scrnum == 0) { aptr->adj_where = CONF_ADJ_ABSOLUTE; aptr->adj_refscreen = NULL; } else { aptr->adj_where = CONF_ADJ_RIGHTOF; - aptr->adj_refscreen = xnfalloc(18); - sprintf(aptr->adj_refscreen, "Screen%d", scrnum - 1); + XNFasprintf(&aptr->adj_refscreen, "Screen%d", scrnum - 1); } ptr->lay_adjacency_lst = (XF86ConfAdjacencyPtr)xf86addListItem((glp)ptr->lay_adjacency_lst, @@ -443,8 +435,7 @@ configureMonitorSection (int screennum) { parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec) - ptr->mon_identifier = malloc(19); - sprintf(ptr->mon_identifier, "Monitor%d", screennum); + XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum); ptr->mon_vendor = strdup("Monitor Vendor"); ptr->mon_modelname = strdup("Monitor Model"); @@ -491,11 +482,9 @@ configureDDCMonitorSection (int screennum) parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec) - ptr->mon_identifier = malloc(19); - sprintf(ptr->mon_identifier, "Monitor%d", screennum); + XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum); ptr->mon_vendor = strdup(ConfiguredMonitor->vendor.name); - ptr->mon_modelname = malloc(12); - sprintf(ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id); + XNFasprintf(&ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id); /* features in centimetres, we want millimetres */ mon_width = 10 * ConfiguredMonitor->features.hsize ; diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index ce144544b..9e2ffaace 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -1284,11 +1284,8 @@ xf86LogInit(void) /* Get the log file name */ if (xf86LogFileFrom == X_DEFAULT) { /* Append the display number and ".log" */ - lf = malloc(strlen(xf86LogFile) + strlen("%s") + - strlen(LOGSUFFIX) + 1); - if (!lf) + if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1) FatalError("Cannot allocate space for the log file name\n"); - sprintf(lf, "%s%%s" LOGSUFFIX, xf86LogFile); xf86LogFile = lf; } diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index ef90fa51c..78f51e166 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -536,8 +536,7 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) for (i = 0; i < xf86NumScreens; i++) { if (xf86Screens[i]->name == NULL) { - xf86Screens[i]->name = xnfalloc(strlen("screen") + 10 + 1); - sprintf(xf86Screens[i]->name, "screen%d", i); + XNFasprintf(&xf86Screens[i]->name, "screen%d", i); xf86MsgVerb(X_WARNING, 0, "Screen driver %d has no name set, using `%s'.\n", i, xf86Screens[i]->name); diff --git a/hw/xfree86/common/xf86ShowOpts.c b/hw/xfree86/common/xf86ShowOpts.c index eac25d701..ce8609081 100644 --- a/hw/xfree86/common/xf86ShowOpts.c +++ b/hw/xfree86/common/xf86ShowOpts.c @@ -111,6 +111,9 @@ void DoShowOptions (void) { ); for (p = pOption; p->name != NULL; p++) { const char *opttype = optionTypeToSting(p->type); + /* XXX: Why overallocate by 2 bytes? + * Otherwise, this would be strdup() + */ char *optname = malloc(strlen(p->name) + 2 + 1); if (!optname) { continue; diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c index d6898322e..447b19229 100644 --- a/hw/xfree86/common/xf86pciBus.c +++ b/hw/xfree86/common/xf86pciBus.c @@ -1347,9 +1347,9 @@ xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo, pVideo = (struct pci_device *) busData; - GDev->busID = xnfalloc(16); xf86FormatPciBusNumber(pVideo->bus, busnum); - sprintf(GDev->busID, "PCI:%s:%d:%d", busnum, pVideo->dev, pVideo->func); + XNFasprintf(&GDev->busID, "PCI:%s:%d:%d", + busnum, pVideo->dev, pVideo->func); GDev->chipID = pVideo->device_id; GDev->chipRev = pVideo->revision; diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c index d7c928b4c..8cfac84e0 100644 --- a/hw/xfree86/common/xf86sbusBus.c +++ b/hw/xfree86/common/xf86sbusBus.c @@ -706,11 +706,9 @@ xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec *GDev) sparcPromClose(); } if (promPath) { - GDev->busID = xnfalloc(strlen(promPath) + 6); - sprintf(GDev->busID, "SBUS:%s", promPath); + XNFasprintf(&GDev->busID, "SBUS:%s", promPath); free(promPath); } else { - GDev->busID = xnfalloc(12); - sprintf(GDev->busID, "SBUS:fb%d", sBus->fbNum); + XNFsprintf(&GDev->busID, "SBUS:fb%d", sBus->fbNum); } } diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c index fe99a2dcc..1d83630a5 100644 --- a/hw/xfree86/dri/dri.c +++ b/hw/xfree86/dri/dri.c @@ -2426,13 +2426,10 @@ DRICreatePCIBusID(const struct pci_device * dev) { char *busID; - busID = malloc(20); - if (busID == NULL) + if (asprintf(&busID, "pci:%04x:%02x:%02x.%d", + dev->domain, dev->bus, dev->dev, dev->func) == -1) return NULL; - snprintf(busID, 20, "pci:%04x:%02x:%02x.%d", dev->domain, dev->bus, - dev->dev, dev->func); - return busID; } diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c index 06d082b34..1f6933a3b 100644 --- a/hw/xfree86/loader/loadmod.c +++ b/hw/xfree86/loader/loadmod.c @@ -406,22 +406,22 @@ FindModuleInSubdir(const char *dirpath, const char *module) snprintf(tmpBuf, PATH_MAX, "lib%s.so", module); if (strcmp(direntry->d_name, tmpBuf) == 0) { - ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1); - sprintf(ret, "%s%s", dirpath, tmpBuf); + if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1) + ret = NULL; break; } snprintf(tmpBuf, PATH_MAX, "%s_drv.so", module); if (strcmp(direntry->d_name, tmpBuf) == 0) { - ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1); - sprintf(ret, "%s%s", dirpath, tmpBuf); + if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1) + ret = NULL; break; } snprintf(tmpBuf, PATH_MAX, "%s.so", module); if (strcmp(direntry->d_name, tmpBuf) == 0) { - ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1); - sprintf(ret, "%s%s", dirpath, tmpBuf); + if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1) + ret = NULL; break; } } diff --git a/hw/xfree86/vbe/vbeModes.c b/hw/xfree86/vbe/vbeModes.c index 3f2cae5bf..ea24b61cd 100644 --- a/hw/xfree86/vbe/vbeModes.c +++ b/hw/xfree86/vbe/vbeModes.c @@ -356,8 +356,8 @@ VBESetModeNames(DisplayModePtr pMode) pMode->VDisplay > 10000 || pMode->VDisplay < 0) { pMode->name = strdup("BADMODE"); } else { - pMode->name = xnfalloc(4 + 1 + 4 + 1); - sprintf(pMode->name, "%dx%d", pMode->HDisplay, pMode->VDisplay); + XNFasprintf(&pMode->name, "%dx%d", + pMode->HDisplay, pMode->VDisplay); } } pMode = pMode->next; diff --git a/os/log.c b/os/log.c index 1ad87dfc2..65195ba43 100644 --- a/os/log.c +++ b/os/log.c @@ -177,10 +177,8 @@ LogInit(const char *fname, const char *backup) char *logFileName = NULL; if (fname && *fname) { - logFileName = malloc(strlen(fname) + strlen(display) + 1); - if (!logFileName) + if (asprintf(&logFileName, fname, display) == -1) FatalError("Cannot allocate space for the log file name\n"); - sprintf(logFileName, fname, display); if (backup && *backup) { struct stat buf; @@ -189,13 +187,9 @@ LogInit(const char *fname, const char *backup) char *suffix; char *oldLog; - oldLog = malloc(strlen(logFileName) + strlen(backup) + - strlen(display) + 1); - suffix = malloc(strlen(backup) + strlen(display) + 1); - if (!oldLog || !suffix) + if ((asprintf(&suffix, backup, display) == -1) || + (asprintf(&oldLog, "%s%s", logFileName, suffix) == -1)) FatalError("Cannot allocate space for the log file name\n"); - sprintf(suffix, backup, display); - sprintf(oldLog, "%s%s", logFileName, suffix); free(suffix); if (rename(logFileName, oldLog) == -1) { FatalError("Cannot move old log file \"%s\" to \"%s\"\n", From d2c42b102707db6c1ca9dccc4de9210a43650cb1 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 27 Nov 2010 23:10:46 -0800 Subject: [PATCH 7/8] Replace alloc+strcpy+strcat with asprintf() & XNFasprintf() calls Signed-off-by: Alan Coopersmith Reviewed-by: Mikhail Gusarov --- dix/devices.c | 17 +++++++++++------ hw/xfree86/common/xf86Config.c | 4 +--- hw/xfree86/common/xf86Option.c | 5 +---- hw/xfree86/common/xf86ShowOpts.c | 7 ++----- hw/xfree86/dixmods/extmod/modinit.c | 5 +---- hw/xfree86/loader/loadmod.c | 6 ++---- hw/xfree86/modes/xf86Crtc.c | 8 ++------ 7 files changed, 20 insertions(+), 32 deletions(-) diff --git a/dix/devices.c b/dix/devices.c index 708860ace..6c0dc42a4 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -2524,9 +2524,11 @@ AllocDevicePair (ClientPtr client, char* name, if (!pointer) return BadAlloc; - pointer->name = calloc(strlen(name) + strlen(" pointer") + 1, sizeof(char)); - strcpy(pointer->name, name); - strcat(pointer->name, " pointer"); + if (asprintf(&pointer->name, "%s pointer", name) == -1) { + pointer->name = NULL; + RemoveDevice(pointer, FALSE); + return BadAlloc; + } pointer->public.processInputProc = ProcessOtherEvent; pointer->public.realInputProc = ProcessOtherEvent; @@ -2547,9 +2549,12 @@ AllocDevicePair (ClientPtr client, char* name, return BadAlloc; } - keyboard->name = calloc(strlen(name) + strlen(" keyboard") + 1, sizeof(char)); - strcpy(keyboard->name, name); - strcat(keyboard->name, " keyboard"); + if (asprintf(&keyboard->name, "%s keyboard", name) == -1) { + keyboard->name = NULL; + RemoveDevice(keyboard, FALSE); + RemoveDevice(pointer, FALSE); + return BadAlloc; + } keyboard->public.processInputProc = ProcessOtherEvent; keyboard->public.realInputProc = ProcessOtherEvent; diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index 5f3b8e8be..49d8fa84a 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -208,9 +208,7 @@ xf86ValidateFontPath(char *path) continue; } else { - p1 = xnfalloc(strlen(dir_elem)+strlen(DIR_FILE)+1); - strcpy(p1, dir_elem); - strcat(p1, DIR_FILE); + XNFasprintf(&p1, "%s%s", dir_elem, DIR_FILE); flag = stat(p1, &stat_buf); if (flag == 0) if (!S_ISREG(stat_buf.st_mode)) diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c index af39b2b5a..d49aa310f 100644 --- a/hw/xfree86/common/xf86Option.c +++ b/hw/xfree86/common/xf86Option.c @@ -638,13 +638,10 @@ ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p, newn = n + 2; } else { free(n); - n = malloc(strlen(p->name) + 2 + 1); - if (!n) { + if (asprintf(&n, "No%s", p->name) == -1) { p->found = FALSE; return FALSE; } - strcpy(n, "No"); - strcat(n, p->name); newn = n; } if ((s = xf86findOptionValue(options, newn)) != NULL) { diff --git a/hw/xfree86/common/xf86ShowOpts.c b/hw/xfree86/common/xf86ShowOpts.c index ce8609081..c0fa80ac7 100644 --- a/hw/xfree86/common/xf86ShowOpts.c +++ b/hw/xfree86/common/xf86ShowOpts.c @@ -97,11 +97,8 @@ void DoShowOptions (void) { ); continue; } - pSymbol = malloc( - strlen(xf86DriverList[i]->driverName) + strlen("ModuleData") + 1 - ); - strcpy (pSymbol, xf86DriverList[i]->driverName); - strcat (pSymbol, "ModuleData"); + XNFasprintf(&pSymbol, "%sModuleData", + xf86DriverList[i]->driverName); initData = LoaderSymbol (pSymbol); if (initData) { XF86ModuleVersionInfo *vers = initData->vers; diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c index f4e922cd0..168795d03 100644 --- a/hw/xfree86/dixmods/extmod/modinit.c +++ b/hw/xfree86/dixmods/extmod/modinit.c @@ -146,11 +146,8 @@ extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin) for (i = 0; extensionModules[i].name != NULL; i++) { if (opts) { char *s; - s = (char *)malloc(strlen(extensionModules[i].name) + 5); - if (s) { + if (Xasprinf(&s, "omit%s", extensionModules[i].name) != -1) { pointer o; - strcpy(s, "omit"); - strcat(s, extensionModules[i].name); o = xf86FindOption(opts, s); free(s); if (o) { diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c index 1f6933a3b..3b3511cd1 100644 --- a/hw/xfree86/loader/loadmod.c +++ b/hw/xfree86/loader/loadmod.c @@ -933,16 +933,14 @@ doLoadModule(const char *module, const char *path, const char **subdirlist, * now check if the special data object ModuleData is * present. */ - p = malloc(strlen(name) + strlen("ModuleData") + 1); - if (!p) { + if (asprintf(&p, "%sModuleData", name) == -1) { + p = NULL; if (errmaj) *errmaj = LDR_NOMEM; if (errmin) *errmin = 0; goto LoadModule_fail; } - strcpy(p, name); - strcat(p, "ModuleData"); initdata = LoaderSymbol(p); if (initdata) { ModuleSetupProc setup; diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c index 08d384f66..c4470c353 100644 --- a/hw/xfree86/modes/xf86Crtc.c +++ b/hw/xfree86/modes/xf86Crtc.c @@ -510,7 +510,6 @@ static void xf86OutputSetMonitor (xf86OutputPtr output) { char *option_name; - static const char monitor_prefix[] = "monitor-"; char *monitor; if (!output->name) @@ -520,11 +519,8 @@ xf86OutputSetMonitor (xf86OutputPtr output) output->options = xnfalloc (sizeof (xf86OutputOptions)); memcpy (output->options, xf86OutputOptions, sizeof (xf86OutputOptions)); - - option_name = xnfalloc (strlen (monitor_prefix) + - strlen (output->name) + 1); - strcpy (option_name, monitor_prefix); - strcat (option_name, output->name); + + XNFasprintf(&option_name, "monitor-%s", output->name); monitor = xf86findOptionValue (output->scrn->options, option_name); if (!monitor) monitor = output->name; From 446482efaa3d266266e2a143492a3ec0523622bd Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 28 Nov 2010 09:41:17 -0800 Subject: [PATCH 8/8] Convert cvt code to use XNFasprintf() Requires linking xprintf.c into standalone cvt utility Signed-off-by: Alan Coopersmith Reviewed-by: Mikhail Gusarov Reviewed-by: Julien Cristau --- hw/xfree86/modes/xf86cvt.c | 10 +--------- hw/xfree86/utils/cvt/Makefile.am | 5 ++++- hw/xfree86/utils/cvt/cvt.c | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/hw/xfree86/modes/xf86cvt.c b/hw/xfree86/modes/xf86cvt.c index 1da5fe50b..244f3b9a3 100644 --- a/hw/xfree86/modes/xf86cvt.c +++ b/hw/xfree86/modes/xf86cvt.c @@ -279,15 +279,7 @@ xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced, if (Interlaced) Mode->VTotal *= 2; - { - char Name[256]; - Name[0] = 0; - - snprintf(Name, 256, "%dx%d", HDisplay, VDisplay); - - Mode->name = xnfalloc(strlen(Name) + 1); - memcpy(Mode->name, Name, strlen(Name) + 1); - } + XNFasprintf(&Mode->name, "%dx%d", HDisplay, VDisplay); if (Reduced) Mode->Flags |= V_PHSYNC | V_NVSYNC; diff --git a/hw/xfree86/utils/cvt/Makefile.am b/hw/xfree86/utils/cvt/Makefile.am index 065868257..ba02145b7 100644 --- a/hw/xfree86/utils/cvt/Makefile.am +++ b/hw/xfree86/utils/cvt/Makefile.am @@ -27,7 +27,10 @@ INCLUDES = $(XORG_INCS) \ -I$(top_srcdir)/hw/xfree86/parser # gah -cvt_SOURCES = cvt.c $(top_srcdir)/hw/xfree86/modes/xf86cvt.c +cvt_SOURCES = cvt.c \ + $(top_srcdir)/hw/xfree86/modes/xf86cvt.c \ + $(top_srcdir)/os/xprintf.c + cvt_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) man1_MANS = cvt.man diff --git a/hw/xfree86/utils/cvt/cvt.c b/hw/xfree86/utils/cvt/cvt.c index cf0a479f2..fff500b43 100644 --- a/hw/xfree86/utils/cvt/cvt.c +++ b/hw/xfree86/utils/cvt/cvt.c @@ -25,6 +25,24 @@ #include "xf86.h" +/* Error implementation used by the server code we built in */ +void +Error(const char *str) +{ + perror(str); +} + +/* FatalError implementation used by the server code we built in */ +void +FatalError(const char *f, ...) +{ + va_list args; + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + exit(1); +} + /* xnfalloc implementation used by the server code we built in */ pointer XNFalloc(unsigned long n)