aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2012-07-10 14:59:04 +1000
committernyamatongwe <devnull@localhost>2012-07-10 14:59:04 +1000
commitdb705286b0f31634e3ad1507d67bffb71ff234fd (patch)
tree4b4c68412e3227f3c767b902331cc2a9a2e71a2d /win32
parentda86674832b4a6e9f2cc79142ee8ce5d638e9aaa (diff)
downloadscintilla-mirror-db705286b0f31634e3ad1507d67bffb71ff234fd.tar.gz
Avoid warnings from Visual Studio Code Analysis for unchecked values and a
loop with unclear termination.
Diffstat (limited to 'win32')
-rw-r--r--win32/PlatWin.cxx107
-rw-r--r--win32/ScintillaWin.cxx3
2 files changed, 57 insertions, 53 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index aa98918b8..d791ff45b 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -772,44 +772,46 @@ void SurfaceGDI::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fil
HBITMAP hbmMem = CreateDIBSection(reinterpret_cast<HDC>(hMemDC), &bpih,
DIB_RGB_COLORS, &image, NULL, 0);
- HBITMAP hbmOld = SelectBitmap(hMemDC, hbmMem);
-
- DWORD valEmpty = dwordFromBGRA(0,0,0,0);
- DWORD valFill = dwordFromBGRA(
- static_cast<byte>(GetBValue(fill.AsLong()) * alphaFill / 255),
- static_cast<byte>(GetGValue(fill.AsLong()) * alphaFill / 255),
- static_cast<byte>(GetRValue(fill.AsLong()) * alphaFill / 255),
- static_cast<byte>(alphaFill));
- DWORD valOutline = dwordFromBGRA(
- static_cast<byte>(GetBValue(outline.AsLong()) * alphaOutline / 255),
- static_cast<byte>(GetGValue(outline.AsLong()) * alphaOutline / 255),
- static_cast<byte>(GetRValue(outline.AsLong()) * alphaOutline / 255),
- static_cast<byte>(alphaOutline));
- DWORD *pixels = reinterpret_cast<DWORD *>(image);
- for (int y=0; y<height; y++) {
- for (int x=0; x<width; x++) {
- if ((x==0) || (x==width-1) || (y == 0) || (y == height-1)) {
- pixels[y*width+x] = valOutline;
- } else {
- pixels[y*width+x] = valFill;
+ if (hbmMem) {
+ HBITMAP hbmOld = SelectBitmap(hMemDC, hbmMem);
+
+ DWORD valEmpty = dwordFromBGRA(0,0,0,0);
+ DWORD valFill = dwordFromBGRA(
+ static_cast<byte>(GetBValue(fill.AsLong()) * alphaFill / 255),
+ static_cast<byte>(GetGValue(fill.AsLong()) * alphaFill / 255),
+ static_cast<byte>(GetRValue(fill.AsLong()) * alphaFill / 255),
+ static_cast<byte>(alphaFill));
+ DWORD valOutline = dwordFromBGRA(
+ static_cast<byte>(GetBValue(outline.AsLong()) * alphaOutline / 255),
+ static_cast<byte>(GetGValue(outline.AsLong()) * alphaOutline / 255),
+ static_cast<byte>(GetRValue(outline.AsLong()) * alphaOutline / 255),
+ static_cast<byte>(alphaOutline));
+ DWORD *pixels = reinterpret_cast<DWORD *>(image);
+ for (int y=0; y<height; y++) {
+ for (int x=0; x<width; x++) {
+ if ((x==0) || (x==width-1) || (y == 0) || (y == height-1)) {
+ pixels[y*width+x] = valOutline;
+ } else {
+ pixels[y*width+x] = valFill;
+ }
}
}
- }
- for (int c=0;c<cornerSize; c++) {
- for (int x=0;x<c+1; x++) {
- AllFour(pixels, width, height, x, c-x, valEmpty);
+ for (int c=0;c<cornerSize; c++) {
+ for (int x=0;x<c+1; x++) {
+ AllFour(pixels, width, height, x, c-x, valEmpty);
+ }
+ }
+ for (int x=1;x<cornerSize; x++) {
+ AllFour(pixels, width, height, x, cornerSize-x, valOutline);
}
- }
- for (int x=1;x<cornerSize; x++) {
- AllFour(pixels, width, height, x, cornerSize-x, valOutline);
- }
- BLENDFUNCTION merge = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
+ BLENDFUNCTION merge = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
- AlphaBlendFn(reinterpret_cast<HDC>(hdc), rc.left, rc.top, width, height, hMemDC, 0, 0, width, height, merge);
+ AlphaBlendFn(reinterpret_cast<HDC>(hdc), rc.left, rc.top, width, height, hMemDC, 0, 0, width, height, merge);
- SelectBitmap(hMemDC, hbmOld);
- ::DeleteObject(hbmMem);
+ SelectBitmap(hMemDC, hbmOld);
+ ::DeleteObject(hbmMem);
+ }
::DeleteDC(hMemDC);
} else {
BrushColor(outline);
@@ -832,26 +834,28 @@ void SurfaceGDI::DrawRGBAImage(PRectangle rc, int width, int height, const unsig
unsigned char *image = 0;
HBITMAP hbmMem = CreateDIBSection(reinterpret_cast<HDC>(hMemDC), &bpih,
DIB_RGB_COLORS, reinterpret_cast<void **>(&image), NULL, 0);
- HBITMAP hbmOld = SelectBitmap(hMemDC, hbmMem);
+ if (hbmMem) {
+ HBITMAP hbmOld = SelectBitmap(hMemDC, hbmMem);
- for (int y=height-1; y>=0; y--) {
- for (int x=0; x<width; x++) {
- unsigned char *pixel = image + (y*width+x) * 4;
- unsigned char alpha = pixelsImage[3];
- // Input is RGBA, output is BGRA with premultiplied alpha
- pixel[2] = (*pixelsImage++) * alpha / 255;
- pixel[1] = (*pixelsImage++) * alpha / 255;
- pixel[0] = (*pixelsImage++) * alpha / 255;
- pixel[3] = *pixelsImage++;
+ for (int y=height-1; y>=0; y--) {
+ for (int x=0; x<width; x++) {
+ unsigned char *pixel = image + (y*width+x) * 4;
+ unsigned char alpha = pixelsImage[3];
+ // Input is RGBA, output is BGRA with premultiplied alpha
+ pixel[2] = (*pixelsImage++) * alpha / 255;
+ pixel[1] = (*pixelsImage++) * alpha / 255;
+ pixel[0] = (*pixelsImage++) * alpha / 255;
+ pixel[3] = *pixelsImage++;
+ }
}
- }
- BLENDFUNCTION merge = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
+ BLENDFUNCTION merge = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
- AlphaBlendFn(reinterpret_cast<HDC>(hdc), rc.left, rc.top, rc.Width(), rc.Height(), hMemDC, 0, 0, width, height, merge);
+ AlphaBlendFn(reinterpret_cast<HDC>(hdc), rc.left, rc.top, rc.Width(), rc.Height(), hMemDC, 0, 0, width, height, merge);
- SelectBitmap(hMemDC, hbmOld);
- ::DeleteObject(hbmMem);
+ SelectBitmap(hMemDC, hbmOld);
+ ::DeleteObject(hbmMem);
+ }
::DeleteDC(hMemDC);
}
@@ -2491,14 +2495,13 @@ void ListBoxX::SetList(const char *list, char separator, char typesep) {
// the listbox is not visible.
SetRedraw(false);
Clear();
- size_t size = strlen(list) + 1;
- char *words = new char[size];
+ size_t size = strlen(list);
+ char *words = new char[size+1];
lti.SetWords(words);
- memcpy(words, list, size);
+ memcpy(words, list, size+1);
char *startword = words;
char *numword = NULL;
- int i = 0;
- for (; words[i]; i++) {
+ for (size_t i=0; i < size; i++) {
if (words[i] == separator) {
words[i] = '\0';
if (numword)
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index c2727607b..80abc69d9 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -385,7 +385,8 @@ void ScintillaWin::Initialise() {
// Find TrackMouseEvent which is available on Windows > 95
HMODULE user32 = ::GetModuleHandle(TEXT("user32.dll"));
- TrackMouseEventFn = (TrackMouseEventSig)::GetProcAddress(user32, "TrackMouseEvent");
+ if (user32)
+ TrackMouseEventFn = (TrackMouseEventSig)::GetProcAddress(user32, "TrackMouseEvent");
if (TrackMouseEventFn == NULL) {
// Windows 95 has an emulation in comctl32.dll:_TrackMouseEvent
HMODULE commctrl32 = ::LoadLibrary(TEXT("comctl32.dll"));