C28112 / 3

时间:2016-12-19 19:00:39

标签: visual-c++ code-analysis volatile visual-studio-2017

我收到了一些代码分析问题:

  

(774):警告C28113:通过a访问本地变量lAbort   互锁功能:这是一种不寻常的用法   重新考虑。

     

(775):警告C28112:通过a访问的变量(lAbort)   必须始终通过互锁来访问互锁功能   功能。见第774行:访问变量并不总是安全的   可以通过Interlocked *系列函数访问   其他方式。

来自此代码:

BOOL CHttpDownloader::Abort()
{
  volatile LONG lAbort = 0;
  InterlockedExchange(&lAbort, m_lAbort);
  return (lAbort != 0);
}

我承认这个代码/类甚至不是我的。原作者现在不支持它,我自己也没有使用过这些类型的volatile变量。

但是,它始终有效,并且不正确地修改代码来解决警告。

1 个答案:

答案 0 :(得分:0)

作者修改了这些课程。该方法现在看起来像这样:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\Joel\Documents\Projects\Forms>gradlew installButlerApk
Picked up _JAVA_OPTIONS: -XX:ParallelGCThreads=2
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon:
https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html.
Incremental java compilation is an incubating feature.                                               
:app:installButlerApk                                                                                
Verifying test-butler installation in emulators
Emulator: List of devices attached   
> Building 0% > :app:installButlerApk

以下是修订后的课程:

http://www.naughter.com/httpdownloaddlg.html