Page 1 of 1

Strange bug

Posted: Mon Jun 15, 2009 3:02 am
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.

Posted: Mon Jun 15, 2009 7:56 am
by DoubleDutch
If I get an invalid memory access - it's often on the wrong line too. Wierd.

Posted: Mon Jun 15, 2009 11:26 am
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.

Posted: Mon Jun 15, 2009 11:57 am
by Fluid Byte
Can we have a working snippet please?

Posted: Mon Jun 15, 2009 12:14 pm
by DoubleDutch
I think there is a working (or non working - depending on your point of view) snippet in the 1st post???

Posted: Mon Jun 15, 2009 12:31 pm
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?

Posted: Mon Jun 15, 2009 12:34 pm
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

Posted: Mon Jun 15, 2009 1:09 pm
by DoubleDutch
Ahh - sorry, just taken another look - your right.