delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/03/23/05:46:11

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: Re: strange comparison error
Date: Tue, 23 Mar 2004 11:38:39 +0100
Organization: Telefonica Data Espagna
Lines: 67
Message-ID: <opr5a86pt9wfff31@news.mad.ttd.net>
References: <opr49vxpzbwfff31 AT news DOT mad DOT ttd DOT net> <dtgu50pfg2q36oqa394ep9gqnag1tt132g AT 4ax DOT com>
NNTP-Posting-Host: 100.red-80-34-252.pooles.rima-tde.net
Mime-Version: 1.0
X-Trace: nsnmrro2-gest.nuria.telefonica-data.net 1080038482 17872 80.34.252.100 (23 Mar 2004 10:41:22 GMT)
X-Complaints-To: usenet AT nsnmrro2-gest DOT nuria DOT telefonica-data DOT net
NNTP-Posting-Date: Tue, 23 Mar 2004 10:41:22 +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

>> pcampo=reg+ncampo+relativo*nc;   // for example

> remember C address arithmetic works in units of t_field: multiplies
> ncampo+relativo*nc by sizeof t_field before adding to reg; are you
> sure you need to multiply relativo by nc here? you are adding relativo
> * nc t_field objects; how big is nc here?

Yes, I want to point to certain struct in a table. 'relativo' gets 1 or -1 
to sum or rest the offset 'nc', that is a little value, between 3 and 1 in 
this case. But the result of 'pcampo' is always grater than 'reg' (I will 
put another assertion to ensure that, though I'm convinced this is not 
failing)

>> if (pcampo>reg+MAXFIELDS) {     // intercept huge (bad) values
> multiplies MAXFIELDS by sizeof t_field before adding to reg

Yes, I write that instead of "if ((int)(pcampo-reg)>MAXFIELDS)", it is 
something natural for me. I use pointers all the time.

>> printf("Wrong field number: %d",(int)(pcampo-reg));
> divides the difference between the addresses by sizeof t_field

Yes, here I want to show the number of field in the table, not an address.

>> 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.

> should not be overflow, as scaled value of MAXFIELDS added should only
> be about 450000-480000, although using the subtraction ensures that
> the calculation works in units of t_field instead of bytes, so you're
> less likely to overflow; once again, maybe look at the value of nc to
> see if the earlier calculation of pcampo could have overflowed?

I don't know how. I'll put assertions for each operand. But I cannot 
reproduce the problem so I don't know when I can have more information 
about it.

>> 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

> sizeof t_field/t_campo should be between 90-96 bytes, depending on
> whether adoptamoneda and sincacheatr are compiled as byte sized or
> word sized

It is 88 bytes.
BOOL is typedef int.
NATRIBUTOSCACHEABLES is 13.

Thank you for your exhaustive answer.


-- 
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