DynamoRIO / DynamoRIO/drmemory

false positive GDI USAGE ERROR when using win32 SaveDC/RestoreDC

Open
#1,552 0 comments 0 reactions 0 assignees View on GitHub
Migrated Priority-Medium
Dominant language
C
Stars
2.7k
Forks
290
PR merge metrics
No merged PRs in 30d

Description

_From [bruno.de...@gmail.com](https://code.google.com/u/117401577226317170005/) on May 20, 2014 10:59:54_

the following code gives false positives GDI USAGE ERROR
#

#include

int main(int argc, char\* argv[]) {

```
HDC hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
if(hdc) {
HBRUSH hBrush = CreateSolidBrush(RGB(0xCD,0xCD,0xCD));

int nDC = SaveDC(hdc); // Current

SelectObject(hdc, hBrush);

RestoreDC(hdc, nDC);

DeleteObject(hBrush);
DeleteDC(hdc);
}
return 0;
```

}
============================================================ http://msdn.microsoft.com/en-us/library/dd162945(v=vs.85).aspx The SaveDC function saves the current state of the specified device context (DC) by copying
data describing selected objects and graphic modes (such as the bitmap, brush, palette, font,
pen, region, drawing mode, and mapping mode) to a context stack. http://msdn.microsoft.com/en-us/library/dd162929(v=vs.85).aspx The RestoreDC function restores a device context (DC) to the specified state. The DC is restored
by popping state information off a stack created by earlier calls to the SaveDC function.

Sample report file is attached

**Attachment:** [results.txt](http://code.google.com/p/drmemory/issues/detail?id=1552)

_Original issue: http://code.google.com/p/drmemory/issues/detail?id=1552_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.