TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Duplicate variables

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
dagbj



Joined: 26 Jan 2009
Posts: 4

PostPosted: Fri Oct 16, 2009 4:37 pm    Post subject: Duplicate variables Reply with quote

I'm in the progress of upgrading my scripts from 1.98.0 to 1.99.7 and I've run across
what I suspect to be a bug.

Starting up the client without any script.
#var inF 1
#var inF 2
#var

This gives me the output
################################## VARIABLES ###################################
#VARIABLE {inF}={2}
#VARIABLE {inF}={1}

Not sure this is expected behavior. From what I can tell #var should give a sorted
list of the defined variables.
Entering these variables:
#var inF 1
#var inF 2
#var inB 3
#var inC 4
#var in1 5
#var inD 6
#var inA 7
#var inF 8
#var inF 9
#var inB 10
#var inC 11
#var in1 12
#var inD 13
#var inA 14

gives this #var list like
#VARIABLE {in1}={12}
#VARIABLE {inF}={9}
#VARIABLE {inF}={8}
#VARIABLE {in1}={5}
#VARIABLE {inA}={14}
#VARIABLE {inB}={10}
#VARIABLE {inC}={11}
#VARIABLE {inD}={13}
#VARIABLE {inF}={2}
#VARIABLE {inF}={1}

I have confirmed this behavior both with the precompiled version and build from source. Also tested on Ubuntu, Fedora and RHEL.

Just as a side note inF variable name came from a var that I'm using that is actually called inFight.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Fri Oct 16, 2009 11:34 pm    Post subject: Reply with quote

Looks like the atoll() C function treats "inf" (infinity?) as a special value, regardless of capitalization.

I'm not sure how to deal with this, but if you avoid using INF it looks like things will work.

I've added fixing it to my todo list.
Back to top
View user's profile Send private message Send e-mail
dagbj



Joined: 26 Jan 2009
Posts: 4

PostPosted: Sat Oct 17, 2009 5:48 am    Post subject: Reply with quote

Thanks for looking at this so quick!
I have got the chance to look at it this more closely, and from what I can see atoll is not the one to blame. But I think I've found where one could point the finger at:

In math.c
Code:
double tintoi(char *str)
...
      default:
         return atof(str);


atof() and strtod() treats text starting with inf or nan (regardless of case) as special strings. This I've verified with a small test program.

The name of the function suggest that it should return int: tin-to-i ?
And that does solve the problem regarding vars starting with inf or nan

I've found a workaround, that I haven't been able to test fully yet:

In math.c, added these:

Code:

long long int get_numberll(struct session *ses, char *str)
{
   char result[BUFFER_SIZE];

   mathexp(ses, str, result);

   return tintoll(result);
}

long long int tintoll(char *str)
{
   switch (str[0])
   {
      case '!':
         return !atoll(&str[1]);

      case '~':
         return ~atoll(&str[1]);

      case '+':
         return +atoll(&str[1]);

      case '-':
         return -atoll(&str[1]);

      default:
         return atoll(str);
   }
}

Along with proper declarations in tintin.h

In data.c

Code:

int bsearch_alpha_list(struct listroot *root, char *text, int seek)
...
<<changed>>
   toi = (long long) get_number(root->ses, text);
<<to>>
   toi = get_numberll(root->ses, text);


This is a possible workaround, but I think I would have investigated changing
tintoi to actually return some int value. I don't know enough of the code to
assess the implications and side effects of such a change.

I hope that this is of some help for you.

Regards
Dag
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Sat Oct 17, 2009 9:01 am    Post subject: Reply with quote

tintoi needs to return a double. From the test I ran atoll (which is redefined as strtoll in tintin.h) does the inf/nan thing as well, I could be wrong though.
Back to top
View user's profile Send private message Send e-mail
dagbj



Joined: 26 Jan 2009
Posts: 4

PostPosted: Sat Oct 17, 2009 9:07 am    Post subject: Reply with quote

I made a small program to test the various converters:
Code:

#include <stdio.h>
#include <stdlib.h>

void testconvertA(char *v);
void testconvertB(char *str);
void testconvertC(char *str);

main()
{
   testconvertA("0");
   testconvertA("10");
   testconvertA("inf");
   testconvertA("inFight");
   testconvertA("Blah");
   testconvertA("nan");
   testconvertA("NaN");
   testconvertA("nanbread");

}

void testconvertA(char *v)
{
   long long int result = strtoll(v, NULL, 10);
   printf("result of %s = %d\n", v, result);
}

void testconvertB(char *str)
{
   double result = atof(str);
   printf("result of %s = %f\n", str, result);
}

void testconvertC(char *str)
{
   double result = strtod(str, NULL);
   printf("result of %s = %f\n", str, result);
}


strtoll() at my computer gives this result:
Code:
result of 0 = 0
result of 10 = 10
result of inf = 0
result of inFight = 0
result of Blah = 0
result of nan = 0
result of NaN = 0
result of nanbread = 0

But this can be library dependent of course.

I will run a test later today with the workaround. Usually 1.99.7 crashes after an hour or two, witch I suspect is connected to the inf-problematic.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Sat Oct 17, 2009 3:53 pm    Post subject: Reply with quote

The whole thing is kind of weird. I added a check in tintoi to have it return 0 when it finds a non digit.
Back to top
View user's profile Send private message Send e-mail
dagbj



Joined: 26 Jan 2009
Posts: 4

PostPosted: Sun Oct 18, 2009 7:31 am    Post subject: Reply with quote

That sounds like a solution. Otherwise I've given the workaround a go, and it looks like it solves the problem that I've got.

Looking forward to the next update.

regards
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group