PVS-Studioã¹ã¿ãã£ãã¯ã¢ãã©ã€ã¶ãŒã®éçºäžãããŸããŸãªæ¹åã§éçºãè©Šã¿ãŠããŸãããããã£ãŠãç§ãã¡ã®ããŒã ã¯IDEïŒVisual StudioãRiderïŒã®ãã©ã°ã€ã³ã«åãçµãã§ãããCIãšã®çµ±åãæ¹åããŠããŸããUnityã®ãããžã§ã¯ãåæã®å¹çãäžããããšããç§ãã¡ã®åªå ç®æšã®1ã€ã§ããéçåæã«ããããã®ã²ãŒã ãšã³ãžã³ã䜿çšããããã°ã©ãã¯ããœãŒã¹ã³ãŒãã®å質ãåäžããããããžã§ã¯ãã§ã®äœæ¥ãç°¡ç¥åã§ãããšèããŠããŸãããããã£ãŠãUnityåãã«éçºããŠããäŒæ¥ã®éã§PVS-Studioã®äººæ°ãé«ããããšæããŸãããã®ã¢ã€ãã¢ãå®è£ ããæåã®ã¹ãããã®1ã€ã¯ããšã³ãžã³ã§å®çŸ©ãããã¡ãœããã®ã¢ãããŒã·ã§ã³ãèšè¿°ããããšã§ãããããã«ãããã¢ãããŒã·ã§ã³ä»ãã¡ãœããã®åŒã³åºãã«é¢é£ä»ããããã³ãŒãã®æ£ç¢ºããå¶åŸ¡ã§ããŸãã
åæžã
泚éã¯ãæãéèŠãªã¢ãã©ã€ã¶ãŒã¡ã«ããºã ã®1ã€ã§ãããããã¯ãåŒæ°ãæ»ãå€ãããã³èªåçã«ææ¡ã§ããªãã¡ãœããã®å éšæ©èœã«é¢ããããŸããŸãªæ å ±ãæäŸããŸããåæã«ã泚éããã°ã©ããŒã¯ãææžåãšåžžèã«åºã¥ããŠãã¡ãœããã®ããããã®å éšæ§é ãšãã®äœæ¥ã®æ©èœãææ¡ã§ããŸãã
ããšãã°ãè¿ãããå€ã䜿çšãããŠããªãå ŽåãGetComponentã¡ãœããã®åŒã³åºãã¯å°ãå¥åŠã«èŠããŸããã§ãããã®ééãïŒã©ãããããŸããŠããã¡ãããããã¯åã«å¿ããããèŠæšãŠãããäœåãªææŠã§ãããããããŸããããŸãã¯ãããã€ãã®éèŠãªå²ãåœãŠãæ¬ èœããŠããå¯èœæ§ããããŸãã泚éã¯ãã¢ãã©ã€ã¶ãŒãåæ§ã®ãšã©ãŒãä»ã®å€ãã®ãšã©ãŒãèŠã€ããã®ã«åœ¹ç«ã¡ãŸãã
ãã¡ãããã¢ãã©ã€ã¶ãŒçšã®å€ãã®æ³šéããã§ã«æžããŠããŸããããšãã°ãSystemåå空éã®ã¢ãããŒã·ã§ã³ä»ãã¯ã©ã¹ã¡ãœãããããã«ãããã€ãã®ã¡ãœããã«èªåçã«æ³šéãä»ããã¡ã«ããºã ããããŸããããã«ã€ããŠè©³ããã¯ããã¡ããã芧ãã ããããã®èšäºã§ã¯ãC ++ã§ãããžã§ã¯ããåæããPVS-Studioã®éšåã«ã€ããŠè©³ãã説æããŠããŸãããã ããCïŒãšC ++ã®æ³šéã®åäœã«ã¯æ確ãªéãã¯ãããŸããã
Unityã¡ãœããã®ã¢ãããŒã·ã§ã³ãæžã
Unityã䜿çšããŠãããžã§ã¯ãã®ã³ãŒãã¬ãã¥ãŒã®å質ãåäžãããããåªããŠããããããã®ãšã³ãžã³ã®ã¡ãœããã«æ³šéãä»ããããšã決å®ãããŸããã
ããšããšã®ã¢ã€ãã¢ã¯ãã¢ãããŒã·ã§ã³ã§ãã¹ãŠã®Unityã¡ãœãããã«ããŒããããšã§ãããããããã®å€ãããããŸããããã®çµæãæãäžè¬çã«äœ¿çšãããã¯ã©ã¹ã®ã¡ãœããã«æ³šéãä»ããããšããå§ããããšã«ããŸããã
æ å ±åé
ãŸããä»ã®ã¯ã©ã¹ããã䜿çšé »åºŠã®é«ãã¯ã©ã¹ãèŠã€ããå¿ èŠããããŸãããããã«ãéèŠãªåŽé¢ã¯ã泚éã®çµæãåéããæ©èœãæäŸããããšã§ã-æžããã泚éãåå ã§ã¢ãã©ã€ã¶ãŒãå®éã®ãããžã§ã¯ãã§æ€åºããæ°ãããšã©ãŒããããã£ãŠãæåã®ã¹ãããã¯ãé¢é£ãããªãŒãã³ãœãŒã¹ãããžã§ã¯ããèŠã€ããããšã§ãããããããããã¯ããã»ã©ç°¡åã§ã¯ãªãããšãããããŸããã
åé¡ã¯ãèŠã€ãã£ããããžã§ã¯ãã®å€ãããœãŒã¹ã³ãŒãã®ç¹ã§éåžžã«å°ããããšã§ãããã®ããããšã©ãŒãããå Žåããšã©ãŒã¯ããã»ã©å€ããªããUnityã®ã¡ãœããã«ç¹ã«é¢é£ããããžãã£ããèŠã€ããå¯èœæ§ã¯ããã«äœããªããŸãã Unityåºæã®ã¯ã©ã¹ãå®éã«ã¯äœ¿çšããªãã£ãïŒãŸãã¯ãŸã£ãã䜿çšããªãã£ãïŒãããžã§ã¯ãããããŸãããã説æã«ãããšããããã¯äœããã®åœ¢ã§ãšã³ãžã³ã«æ¥ç¶ãããŠããŸããããã®ãããªçºèŠã¯ãç®åã®ä»äºã«ã¯å®å šã«äžåãã§ããã
ãã¡ãããæã ç§ã¯å¹žéã§ãããããšãã°ããã®ã³ã¬ã¯ã·ã§ã³ã®å®ç³ã¯MixedRealityToolkitã§ãããã®äžã«ã¯ãŸãšããªã³ãŒãããã§ã«ãããŸããã€ãŸãããã®ãããªãããžã§ã¯ãã§ã®Unityã¡ãœããã®äœ¿çšã«é¢ããåéãããçµ±èšã¯ããå®å šã«ãªããŸãã
ãããã£ãŠããšã³ãžã³ã®æ©èœã䜿çšããŠ20ã®ãããžã§ã¯ããæ¡çšãããŸãããæãäžè¬çã«äœ¿çšãããã¯ã©ã¹ãèŠã€ããããã«ãRoslynããŒã¹ã®ãŠãŒãã£ãªãã£ãUnityããã®ã¡ãœããåŒã³åºããã«ãŠã³ãããããã«äœæãããŸãããã¡ãªã¿ã«ããã®ãããªããã°ã©ã ã¯éçã¢ãã©ã€ã¶ãŒãšåŒã¶ããšãã§ããŸããçµå±ã®ãšãããããªããããã«ã€ããŠèããã°ã圌女ã¯ãããžã§ã¯ãèªäœãèµ·åããããšã«é Œãããšãªããæ¬åœã«ãœãŒã¹ã³ãŒããåæããŸãã
æžããããã¢ãã©ã€ã¶ãŒãã¯ã¯ã©ã¹ãèŠã€ããããšãå¯èœã«ããŸãããèŠã€ãããããããžã§ã¯ãã§ã®å¹³å䜿çšé »åºŠã¯æé«ã§ãïŒ
- UnityEngine.Vector3
- UnityEngine.Mathf
- UnityEngine.Debug
- UnityEngine.GameObject
- UnityEngine.Material
- UnityEditor.EditorGUILayout
- UnityEngine.Component
- UnityEngine.Object
- UnityEngine.GUILayout
- UnityEngine.Quaternion
- çã
ãã¡ãããããã¯ãããã®ã¯ã©ã¹ãå®éã«éçºè ã«ãã£ãŠé »ç¹ã«äœ¿çšãããããšã決ããŠæå³ããŸãã-çµå±ã®ãšããããã®ãããªå°ããªãããžã§ã¯ãã®ãµã³ãã«ã«åºã¥ãçµ±èšã¯ããŸãä¿¡é Œã§ããŸããããã ãããã®æ å ±ãéå§ããããšã§ãå°ãªããšãã©ããã§äœ¿çšãããŠããã¯ã©ã¹ã®ã¡ãœããã«ç¢ºå®ã«æ³šéãä»ããããšãã§ããŸããã
泚é
å¿ èŠãªæ å ±ãååŸãããã次ã¯å®éã®ã¢ãããŒã·ã§ã³ãéå§ããŸãããã®åé¡ã®çã®å©åè ã¯ããã¹ããããžã§ã¯ããäœæãããããã¥ã¡ã³ããšUnityãšãã£ã¿ãŒã§ãããããã¯ãããã¥ã¡ã³ãã§æå®ãããŠããªãããã€ãã®ç¹ã確èªããããã«å¿ èŠã§ãããããšãã°ãåŒæ°ã«nullãæž¡ããšãšã©ãŒãçºçããã®ãããããšãããã°ã©ã ãåé¡ãªãåäœãç¶ããã®ãã¯åžžã«æ確ã§ã¯ãããŸããã§ããããã¡ãããååãšããŠnullãæž¡ãããšã¯å®å šã«è¯ãããšã§ã¯ãããŸãããããã®å Žåãå®è¡ã®ã¹ã¬ãããäžæãããšã©ãŒããŸãã¯Unityãšãã£ã¿ãŒã«ãã£ãŠãšã©ãŒãšããŠãã°ã«èšé²ããããšã©ãŒã®ã¿ãèæ ®ããŸããã
ãã®ãããªãã§ãã¯äžã«ãããã€ãã®æ¹æ³ã®äœæ¥ã®èå³æ·±ãç¹åŸŽãèŠã€ãããŸãããããšãã°ãã³ãŒããå®è¡ãã
MeshRenderer renderer = cube.GetComponent<MeshRenderer>();
Material m = renderer.material;
List<int> outNames = null;
m.GetTexturePropertyNameIDs(outNames);
Unityãšãã£ã¿ãŒèªäœãã¯ã©ãã·ã¥ãããšããäºå®ã«ã€ãªãããŸãããéåžžããã®ãããªå ŽåãçŸåšã®ã¹ã¯ãªããã®å®è¡ãäžæããã察å¿ãããšã©ãŒããã°ã«èšé²ãããŸãããã¡ãããéçºè ããããé »ç¹ã«æžãããšã¯ãŸããããŸããããUnityãšãã£ã¿ãŒãéåžžã®ã¹ã¯ãªãããå®è¡ããããšã§ã¯ã©ãã·ã¥ããå¯èœæ§ããããšããäºå®ã¯ããŸãè¯ããããŸãããåãããšããå°ãªããšããã1ã€ã®ã±ãŒã¹ã§çºçããŸãã
MeshRenderer renderer = cube.GetComponent<MeshRenderer>();
Material m = renderer.material;
string keyWord = null;
bool isEnabled = m.IsKeywordEnabled(keyWord);
ãããã®åé¡ã¯Unity Editor 2019.3.10f1ã«é¢é£ããŠããŸãã
çµæã®åé
泚éãä»ããåŸããããçºè¡ãããèŠåã«ã©ã®ããã«åœ±é¿ãããã確èªããå¿ èŠããããŸããéžæãããããžã§ã¯ãããšã«æ³šéãè¿œå ããåã«ããšã©ãŒãå«ããã°ãçæãããŸãããããåç §ãšåŒã³ãŸãã次ã«ãæ°ãã泚éãã¢ãã©ã€ã¶ãŒã«çµã¿èŸŒãŸãããããžã§ã¯ããåãã§ãã¯ãããŸããçæãããèŠåã®ãªã¹ãã¯ã泚éã®ãããã§ãåç §ãªã¹ããšã¯ç°ãªããŸãã
泚éãã¹ãæé ã¯ããããã®ããŒãºã®ããã«ç¹å¥ã«äœæãããCSharpAnalyserTesterããã°ã©ã ã䜿çšããŠèªåçã«å®è¡ãããŸãããããžã§ã¯ãã®åæãéå§ããåŸãçµæã®ãã°ãšåç §ãã°ãæ¯èŒããçžéç¹ã«é¢ããæ å ±ãå«ããã¡ã€ã«ãçæããŸãã
ããã§èª¬æããæ¹æ³ã¯ãæ°ãã蚺æãè¿œå ããããæ¢åã®èšºæãå€æŽããããããšãã«ããã°ã«ã©ã®ãããªå€åãçŸããããèŠã€ããããã«ã䜿çšãããŸãã
åè¿°ã®ããã«ãUnityã®äžã§å€§èŠæš¡ãªãªãŒãã³ãããžã§ã¯ããèŠã€ããã®ã¯å°é£ã§ãããã¢ãã©ã€ã¶ãŒãããèå³æ·±ãå¿çãçæã§ãããããããã¯äžæå¿«ã§ããåæã«ãåç §ãã°ãšæ³šéã®åŸã«åœ¢æããããã°ã®éã«ã¯ãã¯ããã«å€ãã®éãããããŸãã
ããã«ãããããããæžããã泚éã¯ãæ€èšäžã®ãããžã§ã¯ãã®ããã€ãã®çããããã€ã³ããç¹å®ããã®ã«åœ¹ç«ã¡ãŸãããããããŸããäœæ¥ã®æ¥œããçµæã§ãã
ããšãã°ãGetComponentãžã®ããå¥åŠãªåŒã³åºããèŠã€ãããŸããïŒ
void OnEnable()
{
GameObject uiManager = GameObject.Find("UIRoot");
if (uiManager)
{
uiManager.GetComponent<UIManager>();
}
}
ã¢ãã©ã€ã¶ãŒèŠåïŒV3010é¢æ°ãGetComponentãã®æ»ãå€ãå©çšããå¿ èŠããããŸãã-çŸåšã®è¿œå UIEditorWindow.cs 22 ããã¥ã¡ã³ãã«
åºã¥ããŠããã®ã¡ãœããã«ãã£ãŠè¿ãããå€ãäœããã®æ¹æ³ã§äœ¿çšããå¿ èŠããããšçµè«ä»ããã®ã¯è«ççã§ãããããã£ãŠã泚éãä»ãããšãããã«å¿ããŠããŒã¯ãä»ããããŸãããããã«ãåŒã³åºãçµæã¯äœã«ãå²ãåœãŠããããå°ãå¥åŠã«èŠããŸãã ããã«ãè¿œå ã®ã¢ãã©ã€ã¶ãŒããªã¬ãŒã®å¥ã®äŸã次ã«ç€ºããŸãã
public void ChangeLocalID(int newID)
{
if (this.LocalPlayer == null) // <=
{
this.DebugReturn(
DebugLevel.WARNING,
string.Format(
....,
this.LocalPlayer,
this.CurrentRoom.Players == null, // <=
newID
)
);
}
if (this.CurrentRoom == null) // <=
{
this.LocalPlayer.ChangeLocalID(newID); // <=
this.LocalPlayer.RoomReference = null;
}
else
{
// remove old actorId from actor list
this.CurrentRoom.RemovePlayer(this.LocalPlayer);
// change to new actor/player ID
this.LocalPlayer.ChangeLocalID(newID);
// update the room's list with the new reference
this.CurrentRoom.StorePlayer(this.LocalPlayer);
}
}
ã¢ãã©ã€ã¶ãŒã®èŠåïŒ
- V3095 'this.CurrentRoom'ãªããžã§ã¯ãã¯ãnullã«å¯ŸããŠæ€èšŒãããåã«äœ¿çšãããŸããããã§ãã¯è¡ïŒ1709ã1712ã-çŸåšã®LoadBalancingClient.cs 1709ã«è¿œå
- V3125ãthis.LocalPlayerããªããžã§ã¯ãã¯ãnullã«å¯ŸããŠæ€èšŒãããåŸã«äœ¿çšãããŸããããã§ãã¯è¡ïŒ1715ã1707ã-è¿œå ã®çŸåšã®LoadBalancingClient.cs 1715
PVS-Studioã¯LocalPlayerãstring.Formatã«æž¡ãããšã«æ³šæãæã£ãŠããªãããšã«æ³šæããŠãã ããããããŠãã³ãŒãã¯æå³çã«æžãããããã«èŠããŸãã
ãã®å Žåã泚éã®å¹æã¯ããã»ã©æçœã§ã¯ãããŸããããããããããã®ããžãã£ããåºçŸãããã®ã¯åœŒãã§ãããåé¡ãçºçããŸã-ãªããããã®èŠåã¯ä»¥åã«ã¯ãªãã£ãã®ã§ããïŒ
å®éã®ãšãããDebugReturnã¡ãœããã§ããã€ãã®åŒã³åºããè¡ãããçè«çã«ã¯CurrentRoomããããã£ã®å€ã«åœ±é¿ãäžããå¯èœæ§ããããŸãã
public virtual void DebugReturn(DebugLevel level, string message)
{
#if !SUPPORTED_UNITY
Debug.WriteLine(message);
#else
if (level == DebugLevel.ERROR)
{
Debug.LogError(message);
}
else if (level == DebugLevel.WARNING)
{
Debug.LogWarning(message);
}
else if (level == DebugLevel.INFO)
{
Debug.Log(message);
}
else if (level == DebugLevel.ALL)
{
Debug.Log(message);
}
#endif
}
ã¢ãã©ã€ã¶ãŒã¯åŒã³åºãããã¡ãœããã®æ©èœãèªèããŠããªããããããããã©ã®ããã«ç¶æ³ã«åœ±é¿ãäžãããã¯äžæã§ãããã®ãããPVS-Studioã¯this.CurrentRoomã®å€ãDebugReturnã¡ãœããã®æäœäžã«å€æŽãããå¯èœæ§ããããšæ³å®ããŠãããããããã«æ€èšŒãè¡ãããŸãã
ã¢ãããŒã·ã§ã³ã¯ãDebugReturnå ã§åŒã³åºãããã¡ãœãããä»ã®å€æ°ã®å€ã«åœ±é¿ããªããšããæ å ±ãæäŸããŸããããããã£ãŠãnullãã©ããããã§ãã¯ããåã«å€æ°ã䜿çšããããšã¯çãããããšã§ãã
çµè«
ãŸãšãããšãUnityåºæã®ã¡ãœããã«ã¢ãããŒã·ã§ã³ãä»ããããšã§ããã®ãšã³ãžã³ã䜿çšãããããžã§ã¯ãã§ããŸããŸãªãšã©ãŒãèŠã€ããããšãã§ããããšã¯ééããããŸãããããã«ãããããããå©çšå¯èœãªãã¹ãŠã®ã¡ãœããã®ã¢ãããŒã·ã§ã³ãã«ããŒããã«ã¯ãå€ãã®æéãå¿ èŠã«ãªããŸããæãé »ç¹ã«äœ¿çšããããã®ã«æåã«æ³šéãä»ããæ¹ãå¹ççã§ãããã ããã©ã®ã¯ã©ã¹ãããé »ç¹ã«äœ¿çšãããããç解ããã«ã¯ãã³ãŒãããŒã¹ã倧ããé©åãªãããžã§ã¯ããå¿ èŠã§ããããã«ã倧èŠæš¡ãªãããžã§ã¯ãã§ã¯ã泚éã®å¹æãããé©åã«å¶åŸ¡ã§ããŸããè¿ãå°æ¥ãããããã¹ãŠã«å¯ŸåŠããŠãããŸãã
ã¢ãã©ã€ã¶ãŒã¯åžžã«éçºãããæ¹è¯ãããŠããŸããUnityã¡ãœããã«ã¢ãããŒã·ã§ã³ãè¿œå ããããšã¯ããã®æ©èœãæ¡åŒµãã1ã€ã®äŸã«ãããŸããããããã£ãŠãæéã®çµéãšãšãã«ãPVS-Studioã®ããã©ãŒãã³ã¹ã¯åäžããŸãããããã£ãŠãPVS-StudioããŸã è©ŠããŠããªãå Žåã¯ã察å¿ããããŒãžããããŠã³ããŒãããŠä¿®æ£ããŠãã ãããããã§ãããŸããŸãªãããžã§ã¯ãããã§ãã¯ããŠãã¢ãã©ã€ã¶ãŒã®æ©èœãç解ããããã®ãã©ã€ã¢ã«ããŒãååŸã§ããŸãã
ãã®èšäºãè±èªã話ããŠãŒã¶ãŒãšå ±æãããå Žåã¯ã翻蚳ãªã³ã¯Nikita Lipilinã䜿çšããŠãã ãããPVS-Studioã¢ãã©ã€ã¶ãŒãUnityãããžã§ã¯ãã§ããã«å€ãã®ãšã©ãŒãæ€åºãå§ããæ¹æ³ã