Strange bug

Just starting out? Need help? Post your questions and find answers here.
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Strange bug

Post by dhouston »

This took a bit of time to see and I still have no idea how the code got mangled. The code below compiled OK but crashed with an Invalid Memory Access at the 5th line with the cause being the 32nd line.

Code: Select all

    ListViewGadget(#LIST_HOL_CFG,12,top+14,215,30,#PB_ListView_Clickselect)
    y=Year(Date())
    If ReadFile(0, "holiday.txt")    
      While Eof(0)=0      
       temp=UCase(Trim(StringField(ReadString(0),1,";")))  ;===============INVALID MEMORY ACCESS============
        If Len(temp)>0   
          datecode=StringField(temp,2,"=")      
          temp=StringField(temp,1,"=")
          If FindString(datecode,"/",1)
            m=Val(StringField(datecode,1,"/")):d=Val(StringField(datecode,2,"/"))
            If Date(y,m,d,0,0,0)<>-1 
              If StringField(datecode,2,",")="1"
                weekday=DayOfWeek(Date(y,m,d,0,0,0))
                If weekday=0:d+1:EndIf
                If weekday=6
                  If d>1
                    d-1
                  Else
                    If m>1
                      m-1:d=32
                      While Date(y,m,d, 0, 0, 0)=-1:d-1:Wend
                    EndIf  
                  EndIf              
                EndIf  
              EndIf 
              temp=RSet(Str(DayOfYear(Date(y,m,d, 0, 0, 0))),3,"0")+" "+temp
            Else
              temp = "INVALID DATECODE "+datecode
            EndIf  
          Else
            m=m=Val(StringField(datecode,3,","))  ;==============THIS LINE WAS THE CAUSE=================
            d=GetDay(datecode)
            If d>-1
              temp=RSet(Str(DayOfYear(Date(y,m,d, 0, 0, 0))),3,"0")+" "+temp
            Else
              temp = "INVALID DATECODE "+datecode
            EndIf
          EndIf  
          AddGadgetItem(#LIST_HOL_CFG,-1,temp)
          If Len(Trim(holidays))
            holidays+","+StringField(temp,1," ")
          Else
            holidays+StringField(temp,1," ") 
          EndIf  
        EndIf
      Wend
      CloseFile(0)   
    EndIf
    If DayOfWeek(Date(y,12,31,0,0,0))=5
      temp=RSet(Str(DayOfYear(Date(y,12,31, 0, 0, 0))),3,"0")+" New Year's Day "+Str(y+1)
      AddGadgetItem(#LIST_HOL_CFG,-1,temp)
    EndIf
Shouldn't the compiler catch errors like this.

This code was stable for several months before it started crashing and I do not recall editing it so am mystified how the m=m= got there.

BTW, this was under XP Pro & PB 4.30 final.
Last edited by dhouston on Mon Jun 15, 2009 3:21 pm, edited 1 time in total.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

If I get an invalid memory access - it's often on the wrong line too. Wierd.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Post by dhouston »

DoubleDutch wrote:If I get an invalid memory access - it's often on the wrong line too. Wierd.
Yes - I've encountered that before which is why I then went line by line looking for something amiss. But I would expect an error like m=m= (and no colon in the line) to be flagged during the compile.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Can we have a working snippet please?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I think there is a working (or non working - depending on your point of view) snippet in the 1st post???
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

DoubleDutch wrote:I think there is a working (or non working - depending on your point of view) snippet in the 1st post???
No offense, but no, it's not a working snippet... We should always have to copy/paste/run to see the bug, don't you think?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

DoubleDutch wrote:I think there is a working (or non working - depending on your point of view) snippet in the 1st post???
No.

PS: one ? is enuff
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Ahh - sorry, just taken another look - your right.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply