AN UNEXPECTED MISTAKE OCCURRED - by Huacoa

Status : 

 


1
1
Sign in
to vote
ID 773991 Comments
Status Active Workarounds
Type Bug Repros 0
Opened 12/10/2012 8:48:33 PM
Access Restriction Public

Description

#include<stdio.h>
#include<string.h>
char prog[80],token[6];
char ch;
int syn,p,m,n,sum;
int scaner();
char * rwtab[6]={"begin","if","then","while","do","end"};
void main()
{
 p=0;
 printf("\nplease intput string:");
do
{
 ch=getchar();
 prog[p++]=ch;
}while(ch!='#');
p=0;
do
{
 scaner();
 switch(syn)
 {
  case 11:printf("(%d,%d)\n",syn,sum);break;
  case -1:printf("input error\n");  break;
  default:printf("(%d,%s)\n",syn,token);
 }


}while(syn!=0);
getchar();
}
/*词法扫描程序:*/
int scaner()
{
 for(n=0;n<8;n++)
  token[n]=NULL;
  m=0;
  ch=prog[p++];
  while(ch==' ')ch=prog[p++];
  if((ch<='z'&&ch>='a')||(ch<='Z'&&ch>='A'))
  {
   while((ch<='z'&&ch>='a')||(ch<='Z'&&ch>='A')||(ch<='9'&&ch>='0'))
   {
    token[m++]=ch;
    ch=prog[p++];
    }
   token[m++]='\0';
   ch=prog[--p];
   syn=10;
   for(n=0;n<6;n++)
       if(strcmp(token,rwtab[n])==0)
       {
        syn=n+1;
        break;
        }
    }
   else
       if((ch<='9'&&ch>='0'))
         {
          sum=0;
          while((ch<='9'&&ch>='0'))
          {
           sum=sum*10+ch-'0';
           ch=prog[p++];
           }
           ch=prog[--p];
           syn=11;
           }
       else
        switch(ch)

         
 {
          case '<':m=0;token[m++]=ch;
                   ch=prog[p++];
                   if(ch=='>')
                   {
                    syn=21;
                    token[m++]=ch;
                    }
                    else
                        if(ch=='=')
                        {
                         syn=22;
                         token[m++]=ch;
                         }
                         else
                         {
                          syn=20;
                          ch=prog[--p];
                          }
          break;
          case '>':token[m++]=ch;
                   ch=prog[p++];
                   if(ch=='=')
                   {
                   syn=24;
                   token[m++]=ch;
                    }
                   else
                   {
                    syn=23;
                    ch=prog[--p];
                    }
          break;
          case ':':token[m++]=ch;
                   ch=prog[p++];
                   if(ch=='=')
                   {
                    syn=18;
                    token[m++]=ch;
                   }
                    else
                {

                   
  syn=17;
                     ch=prog[--p];
                     }
          break;
          case '+':syn=13;token[0]=ch;break;
          case '-':syn=14;token[0]=ch;break;
          case '*':syn=15;token[0]=ch;break;
          case '/':syn=16;token[0]=ch;break;
          case ':=':syn=18;token[0]=ch;break;
          case '<>':syn=21;token[0]=ch;break;
          case '<=':syn=22;token[0]=ch;break;
          case '>=':syn=24;token[0]=ch;break;
          case '=':syn=25;token[0]=ch;break;
          case ';':syn=26;token[0]=ch;break;
          case '(':syn=27;token[0]=ch;break;
          case ')':syn=28;token[0]=ch;break;
          case '#':syn=0;token[0]=ch;break;
          default:syn=-1;
          }return(syn);
      }
Sign in to post a comment.
Posted by Microsoft on 1/5/2013 at 9:49 PM
Hi Huacoa,

as the community comments suggest, this is very likely indicating a problem in your code. String parsing can be very tricky. The runtime is noticing a buffer overrun.

Make sure your program is bug free. Users on the VC++ can be very helpful. If you still reproduce the problem, be sure to attach a .c or .cpp file with your code, so that we can repro the problem.

HTH,

Ale Contenti
VC++ Dev Manager
Posted by Microsoft on 12/11/2012 at 2:33 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by UnitUniverse on 12/10/2012 at 11:26 PM
@Huacoa:
It's obviously your problems. One of the array has been over filled in your code. Be sure bug-freeing your code before complaining about the compiler.
Posted by UnitUniverse on 12/10/2012 at 11:23 PM
It's obviously your problems. One of the array has been over filled in your code. Be sure bug-freeing your code before complaining about the compiler.
Posted by Microsoft on 12/10/2012 at 8:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)