2016-09-08 2 views
-5

링크를 참조하십시오. 그러나 toParse! = ""는 어쨌든 true로 평가되므로 응용 프로그램이 충돌합니다. 이 라인 newNode.parseString(inside) 그것을 호출 스택에서의 의미 강조와 충돌하기 전에 호출 된 이미지에서문이 실행중인 경우 왜이 값이 false입니까?</p> <p><a href="http://i.imgur.com/gFcamd8.png" rel="nofollow">http://i.imgur.com/gFcamd8.png</a></p> <p>공지 사항 하단에있는 자동차 창을 보여줍니다 toParse = "": (C#을)

public void parseString(string toParse) 
    { 
     while (toParse != "") 
     { 
      string nextLine = readLine(ref toParse); 

      if (nextLine.IndexOf("//") == 0) 
      { 
       comments.Add(nextLine); 
       continue; 
      } 

      if (nextLine.IndexOf(".") == 0) 
      { 
       string[] declarationParts = nextLine.Split(' '); 
       string declarationString = declarationParts[0].Substring(1, declarationParts[0].Length - 1); 
       declarationString = char.ToUpper(declarationString[0]) + declarationString.Substring(1); 
       DirectiveEnum type = (DirectiveEnum)Enum.Parse(typeof(DirectiveEnum), declarationString); 
       string[] attributes = declarationParts.Skip(1).ToArray(); 
       MSILNode newNode = new MSILNode(type); 
       newNode.addAttributes(attributes); 
       toParse = toParse.Trim(); 
       if (toParse != "") 
       { 
        while (toParse[0] != '{' && toParse[0] != '.' && toParse.IndexOf("//") != 0) 
        { 
         nextLine = readLine(ref toParse); 
         attributes = nextLine.Split(' '); 
         newNode.addAttributes(attributes); 
        } 

        if (toParse[0] == '{') 
        { 
         readLine(ref toParse); 
         string inside = separate(ref toParse, "}"); 

         newNode.parseString(inside); 
        } 
       } 
       subNodes.Add(newNode); 
       continue; 
      } 

      Console.WriteLine(nextLine); 
     } 
    } 
+0

toParse의 값은 무엇입니까? –

+0

'toParse'의 길이는 얼마입니까? – siride

+0

참조 op : toParse = "" –

답변

0

:

여기에 전체 방법입니다. 이 줄은 아마도 "~"이되도록 변형시킬 것입니다.

+0

전체 방법을 보여주기 위해 OP를 수정했습니다. parseString()을 호출 할 때 가장 먼저 확인하는 것은 전달 된 문자열이 == ""인지 여부입니다. –

2

이 스냅 샷이 주어진 경우에만 디버깅 세션 중에 발생하는 모든 것을 볼 수 없습니다. 그러나 toParsereadline() (라인 57) 참조를 통해 전달되므로이 함수의 본문에서 값을 변경할 수 있습니다. 원래의 질문에 제공되는 PNG 이미지에서

:

53 if (toParse != "") 
54 { 
55  while (toParse[0] != '{' && toParse[0] != '.' && toParse.IndexOf("//") != 0) 
56  { 
57   nextLine = readLine(ref toParse); 
58   ... 

라인 (53)에서, toParse가 비어 있지 않습니다. 그런 다음 루프의 while 반복 중 하나가 빈 값으로 업데이트됩니다. 이로 인해 배열 인덱스 (즉, while 조건의 toParse[0])에 대한 액세스가 발생하여 예외가 발생합니다.

C#의 ref 키워드에 대한 자세한 내용은 this StackOverflow issue 또는 this official Microsoft documentation을 참조하십시오.

도움이 되었기를 바랍니다.