Subject: x_pager fix

From: Michael Han <[email-masked]>
Date: Tue, 18 Apr 2000 22:01:43 -0700

Hi, I noticed that my compiler throws the following errors on make
(gcc as included in FreeBSD 4.0-STABLE):

FvwmCpp.o: In function `cpp_defs':
/home/mikehan/fvwm/modules/FvwmCpp/FvwmCpp.c(.text+0x4d2): warning:
mktemp() possibly used unsafely; consider using mkstemp()
FvwmM4.o: In function `m4_defs':
/home/mikehan/fvwm/modules/FvwmM4/FvwmM4.c(.text+0x546): warning:
mktemp() possibly used unsafely; consider using mkstemp()
x_pager.c: In function `UpdateWindowShape':
x_pager.c:821: warning: assignment from incompatible pointer type

For x_pager.c, the fix appears trivial. The alloc'd memory needs to be
cast when assigned to the pointer:

diff -u -r1.90 x_pager.c
--- x_pager.c   2000/04/18 16:12:30     1.90
+++ x_pager.c   2000/04/19 04:51:19
@@ -818,7 +818,7 @@
   shape_count =
     ndesks + ((Scr.CurrentDesk < desk1 || Scr.CurrentDesk >desk2) ? 0 : 1);
 
-  shape = alloca (shape_count * sizeof (XRectangle));
+  shape = (XRectangle *)alloca (shape_count * sizeof (XRectangle));
 
   if (shape == NULL)
     return;

This appears to fix the warning, and I'm blithely assuming it works
the same. As far as the mk[s]temp() complaint, the suggestion to use
mkstemp() sounds good, but I don't know if there's some reason not to
use mkstemp().
-- 
[email-masked]                         http://www.best.com/~mikehan/
coffee achiever                              San Francisco, California
"'Why is that toy on your head?' 'Because if I wear it anywhere else, it
chafes.'" - Chris Knight
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Wed, 19 Apr 2000 11:39:09 +0200

> cast when assigned to the pointer:

...

Thanks

I'll apply the patch

Bye

Dominik ^_^

-- 
Dominik Vogt, Agilent Technologies, Dept. BVS
Herrenberger Str.130, 71034 Boeblingen, Germany
phone: 07031/464-4596, fax: 07031/464-3883, [email-masked]
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: [email-masked] (Paul D. Smith)
Date: 19 Apr 2000 10:44:17 -0400

%% Michael Han <[email-masked]> writes:

  mh> As far as the mk[s]temp() complaint, the suggestion to use
  mh> mkstemp() sounds good, but I don't know if there's some reason not
  mh> to use mkstemp().

Not all systems have it, for one thing.  You can get about the same
level of security by using open() with O_CREAT|O_EXCL.

Here is a tempfile open function I implemented recently in GNU make;
it should work on all systems.

You need this in configure.in:

  AC_CHECK_FUNCS(mkstemp mktemp fdopen)

Then this will work (switch to ANSI of course for FVWM):

  extern char *mktemp ();
  extern int mkstemp ();

  FILE *
  open_tmpfile(name, template)
       char **name;
       const char *template;
  {
    int fd;

  #if defined HAVE_MKSTEMP || defined HAVE_MKTEMP
  # define TEMPLATE_LEN   strlen (template)
  #else
  # define TEMPLATE_LEN   L_tmpnam
  #endif
    *name = xmalloc (TEMPLATE_LEN + 1);
    strcpy (*name, template);

  #if defined HAVE_MKSTEMP && defined HAVE_FDOPEN
    /* It's safest to use mkstemp(), if we can.  */
    fd = mkstemp (*name);
    if (fd == -1)
      return 0;
    return fdopen (fd, "w");
  #else
  # ifdef HAVE_MKTEMP
    (void) mktemp (*name);
  # else
    (void) tmpnam (*name);
  # endif

  # ifdef HAVE_FDOPEN
    /* Can't use mkstemp(), but guard against a race condition.  */
    fd = open (*name, O_CREAT|O_EXCL|O_WRONLY, 0600);
    if (fd == -1)
      return 0;
    return fdopen (fd, "w");
  # else
    /* Not secure, but what can we do?  */
    return fopen (*name, "w");
  # endif
  #endif
  }

It's invoked like this.  I already removed all the VMS/DOS/Windows stuff
the GNU make version has for you :)

  #ifdef P_tmpdir
  # define DEFAULT_TMPDIR    P_tmpdir
  #else
  # define DEFAULT_TMPDIR    "/tmp"
  #endif
  #define DEFAULT_TMPFILE     "FvXXXXXX"

    if ((tmpdir = getenv ("TMPDIR")) == NULL || *tmpdir == '\0')
      tmpdir = DEFAULT_TMPDIR;

    template = (char *) alloca (strlen (tmpdir)
                                + sizeof (DEFAULT_TMPFILE) + 1);
    strcpy (template, tmpdir);

    if (template[strlen (template) - 1] != '/')
      strcat (template, "/");

    strcat (template, DEFAULT_TMPFILE);
    outfile = open_tmpfile (&stdin_nm, template);
    if (outfile == 0)
      pfatal_with_name (_("fopen (temporary file)"));

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <[email-masked]>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
   These are my opinions---Nortel Networks takes no responsibility for them.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]