delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/06/04:57:21

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
Organization: Materials Science Centre
To: DJGPP AT DELORIE DOT COM
Date: Thu, 6 Mar 1997 09:50:35 GMT
Subject: gcc -O2 paranoia re `variable may be clobbered by longjmp()'
Message-ID: <41F045F68D5@fs2.mt.umist.ac.uk>

C:\AM>type _.cc
#include<std.h>
#include<stdio.h>
#include<setjmp.h>
int Z(int nargs,char**arg){char*T,U[128]; int j=0; jmp_buf bad;
T=nargs>=2?arg[1]:".";
if(j<6) if(setjmp(bad)) {j++; goto XX;}
strcpy(U,T);
XX: return 1;}

C:\AM>gcc _.cc -Wall -c -O2
_.cc: In function `int Z(int, char **)':
_.cc:4: warning: variable `char * T' might be clobbered by `longjmp' or `vfork'

In this program, where is the risk that longjmp may `clobber' T? This warning
goes away if I remove `strcpy(U,T);'. OK, gcc doesn't know what strcmp() does,
and has to behave as if strcpy() called longjmp() and used every function and
global variable in the program. But DJGPP\INCLUDE\STRING.H declares strcpy()
as `char * strcpy(char *_s1, <<<const>>> char *_s2);', and T is local to Z(),
therefore strcpy() can't alter T (although it may alter *T). Nothing else that
mentions T is in the range jumped over by the setjmp statement.
  If the risk is only from vfork(), this should be stated separately, and
there should be an option to suppress checking for clobbering by vfork().

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019