delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/03/22/12:01:51

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: =?iso-8859-15?Q?Rafael_Garc=EDa?= <rafael-no_spam_please_ AT geninfor DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: strange comparison error
Date: Mon, 22 Mar 2004 17:54:51 +0100
Organization: Telefonica Data Espagna
Lines: 55
Message-ID: <opr49vxpzbwfff31@news.mad.ttd.net>
NNTP-Posting-Host: 100.red-80-34-252.pooles.rima-tde.net
Mime-Version: 1.0
X-Trace: nsnmrro2-gest.nuria.telefonica-data.net 1079974651 8333 80.34.252.100 (22 Mar 2004 16:57:31 GMT)
X-Complaints-To: usenet AT nsnmrro2-gest DOT nuria DOT telefonica-data DOT net
NNTP-Posting-Date: Mon, 22 Mar 2004 16:57:31 +0000 (UTC)
User-Agent: Opera7.11/Win32 M2 build 2887
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I have got an error message today that I cannot reproduce in my working 
machine. I don't understand what could cause it but perhaps some of you can 
give me an idea.

I have something like this:
--------------------------------------------------------
#define MAXFIELDS 5000
...
t_field *pcampo,*reg;
int ncampo,relativo;
...
pcampo=reg+ncampo+relativo*nc;   // for example
...
if (pcampo>reg+MAXFIELDS) {     // intercept huge (bad) values
   printf("Wrong field number: %d",(int)(pcampo-reg));
   return NULL; }
do something with *pcampo
---------------------------------------------------------
Well, this is not complete but that is not the point because it doesn't 
fail now. Nor it failed executing from RHIDE, when I tried to debug it with 
a breakpoint. It only failed in the morning on a machine to which I cannot 
get now.
The problem is at the 'if'. It gave "Wrong field number: 14" but I can't 
understand how can it be 14 pcampo-reg and go into de "if (pcampo>reg+5000) 
". I did solve it changing to "if (pcampo-reg>MAXFIELDS)", but cannot 
understand de difference.
Perhaps that change didn't really solve it, but the mere recompilation 
corrected something. I don't think so.

Could you imagine something can affect this pointer arithmetic? This same 
code is working regularly on other machines running many million times a 
day.

Thank you.


If you think the definition of 't_field' could be important, here it is 
(without translation).

typedef struct {  char *nombre;  int tam;
   char *def;     int vdesp;     int hdesp;     char *buf;     unsigned 
adoptamoneda:1;  #ifndef NOCACHEATR
   BOOL sincacheatr;
   int cacheatrlisto;
   char *cacheatributos[NATRIBUTOSCACHEABLES];
#endif
   } t_campo;


NOCACHEATR is undefined
NATRIBUTOSCACHEABLES is something like 15


-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

- Raw text -


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