Local Variable was change range value but not assigned
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi Matlab Support teams!
I'm using Polyspace R2019a, and i got a problem about local Variable
At line 5970, range value of local variable "u1t_InRnewEndPntIdx" = [0..8],
Please take a look following pic 1:

But at line 5980, range value of local variable "u1t_InRnewEndPntIdx" = [0..17]
Please take a look following pic 2:

u1t_InRnewEndPntIdx is not updated or assigned from line 5971 to 5980, why does it change range value?
Please help me answer the question above.
BR
Hoang Hiep
채택된 답변
Anirban
2020년 12월 16일
Hi,
One of the reasons could be that Code Prover is considering the case where the if branch, where u1t_InRnewEndPntIdx is assigned (line 5970), is bypassed. So the range outside the for loop is a combination of ranges in the if branch and any range u1t_InRnewEndPntIdx had before the for loop.
There is something you can try. Place this line:
#pragma Inspection_Point u1t_InRnewEndPntIdx
in the else branch with the break and see the tooltip on u1t_InRnewEndPntIdx. This might help you confirm this hypothesis.
댓글 수: 8
Hi Anirban
I add the line in else branch.
Range value of u1t_InRnewEndPntIdx is [0..9] at else branch. Please take a look shot below:

And rang value of u1t_InRnewEndPntIdx is [0..9] at line 5981.

Why add "#pragma Inspection_Point u1t_InRnewEndPntIdx" line code, It affects to range value of u1t_InRnewEndPntIdx?
Please help me to explain it.
BR
Is the tooltip in the if branch still 0..8? Can you also place the same pragma right before the for loop and see the range?
That might help us form a hypothesis on what is happening. As always, it is difficult to pinpoint the cause without having the full context of the code (since variables in code are often interrelated in surprising ways). A generic answer is the following:
When you added the #pragma Inspection_Point, you not only added a point where you can see a tooltip, but it also acted as a point that the tool can monitor. When a new monitoring point is added, in some cases, the tool can also acquire more information to propagate forward. As a result, you see a more precise range later. It seems that when Code Prover was earlier showing you 0..17, it was losing precision somewhere (this is not a problem since if Code Prover loses precision, it overapproximates to avoid missing an error). With the new monitoring point, Code Prover showed the more precise range.
Tran Thang
2020년 12월 22일
편집: Tran Thang
2020년 12월 22일
Hi Anirban.
Thank you for your answer.
Is the tooltip in the if branch still 0..8? -> Yes, rang value of it is 0..8.
That might help us form a hypothesis on what is happening. -> Ok, i'll try it. I'll let you know the result later.
My source code is too big, How to know it was losing precision? Do you have option or configuration before i run my project?
One more question about array

Can i insert line of code "#pragma Inspection_Point u1t_ArSrcSignalData[];" for array u1t_ArSrcSignalData[] ?
BR
Hi Anirban.
Can you also place the same pragma right before the for loop and see the range? -> I add the line of code
and Range value of u1t_InRnewEndPntIdx is [0..254]

please let me know more info.
BR
Hi Anirban.
Help me to answer above my questions.
Thank you in advance
Thang Tran
Hi,
Sorry to have raised your hopes, but it is difficult to tell from a visual inspection alone how the ranges are what they are. I was hoping that the pragmas will lead to some answers, but in this specific instance, the pragma only made the analysis more precise, but did not fully explain the situation.
It seems that the loop is definitely entered, that is why the range after the loop is exactly the same as the range in the else branch. But it is not clear where the range in the else branch comes from. For that, the full context of the code is needed. For example:
- There is an orange Out of bounds array index check and a couple of Unreachable code checks inside the loop. These checks might be important to explain the ranges.
- The line 5970 is a macro. The macro expansion (what you see after clicking the M icon on the left) might be useful to understand what is going on. Sometimes what looks like a function call might not be a function call at all.
You will have to contact Support using the link here: https://www.mathworks.com/support/contact_us.html?s_tid=doc2cs
and share the results somehow. Support has all kinds of ways to obfuscate the code received so that you will not have to share the actual code.
To answer your other questions:
- You cannot add the pragma on an entire array.
- The analysis losing precision is not a problem per se because if the range 0..17 does not cause an issue like an overflow, the smaller range 0..9 is already checked and will still not cause an overflow. So, the greens are fine despite the loss of precision. However, the loss of precision does cause a problem of understanding if you are trying to track the ranges. In this case, as I answered before, it would be possible with the full context of the code, to get a sense of what led to the loss of precision and how adding some more information through the pragma in the else branch, the precision is regained. But Technical Support will have to look through the ranges on the other variables in the loop, the checks in the loop and other information provided by the tool. They can also explain to you what they looked for and how they arrived at their explanation.
Tran Thang
2020년 12월 30일
편집: Tran Thang
2020년 12월 30일
Hi Anirban !
I see CP result that have full source?, Besides I can't decide whether given it to Technical Support .
Your answer also help me workaround and solve it partly.
From the bottom, Thank you for your answer.
BR
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Polyspace Bug Finder에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
