Skip to content

Commit

Permalink
Fixes for issues hit in 2013 and 2008 analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
malxau committed Dec 27, 2020
1 parent 38d1865 commit bd29c9d
Show file tree
Hide file tree
Showing 97 changed files with 922 additions and 311 deletions.
15 changes: 10 additions & 5 deletions builtins/history.c
Expand Up @@ -196,7 +196,9 @@ HistoryCreateSynchronousMenu(
}

Result = FALSE;
YoriWinProcessInputForWindow(Parent, &Result);
if (!YoriWinProcessInputForWindow(Parent, &Result)) {
Result = FALSE;
}
if (Result) {
if (!YoriWinListGetActiveOption(List, ActiveOption)) {
Result = FALSE;
Expand Down Expand Up @@ -333,10 +335,13 @@ YoriCmd_HISTORY(
if (ArgC > i + 1) {
DWORD CharsConsumed;
LONGLONG llTemp;
YoriLibStringToNumber(&ArgV[i + 1], TRUE, &llTemp, &CharsConsumed);
LineCount = (DWORD)llTemp;
ArgumentUnderstood = TRUE;
i++;
if (YoriLibStringToNumber(&ArgV[i + 1], TRUE, &llTemp, &CharsConsumed) &&
CharsConsumed > 0) {

LineCount = (DWORD)llTemp;
ArgumentUnderstood = TRUE;
i++;
}
}
} else if (YoriLibCompareStringWithLiteralInsensitive(&Arg, _T("u")) == 0) {

Expand Down
8 changes: 6 additions & 2 deletions builtins/ys.c
Expand Up @@ -531,8 +531,12 @@ YoriCmd_RETURN(
LONGLONG LlExitCode;
DWORD CharsConsumed;

YoriLibStringToNumber(&ArgV[StartArg], TRUE, &LlExitCode, &CharsConsumed);
ExitCode = (DWORD)LlExitCode;
if (!YoriLibStringToNumber(&ArgV[StartArg], TRUE, &LlExitCode, &CharsConsumed) ||
CharsConsumed == 0) {
ExitCode = 0;
} else {
ExitCode = (DWORD)LlExitCode;
}
}

//
Expand Down
18 changes: 13 additions & 5 deletions builtins/z.c
Expand Up @@ -293,14 +293,17 @@ ZNotifyUnload(VOID)
@return If the object resolves to a full path and that path exists, returns
TRUE; otherwise, returns FALSE.
*/
__success(return)
BOOL
ZResolveSpecificationToFullPath(
__in PYORI_STRING OldCurrentDirectory,
__in PYORI_STRING UserSpecification,
__out PYORI_STRING FullNewDir
)
{
YoriLibInitEmptyString(FullNewDir);
YORI_STRING LocalDir;

YoriLibInitEmptyString(&LocalDir);

if (UserSpecification->LengthInChars == 2 &&
((UserSpecification->StartOfString[0] >= 'A' && UserSpecification->StartOfString[0] <= 'Z') ||
Expand Down Expand Up @@ -328,22 +331,27 @@ ZResolveSpecificationToFullPath(
return FALSE;
}

YoriLibGetCurrentDirectoryOnDrive(UserSpecification->StartOfString[0], FullNewDir);
if (!YoriLibGetCurrentDirectoryOnDrive(UserSpecification->StartOfString[0], &LocalDir)) {
return FALSE;
}

} else {

YoriLibUserStringToSingleFilePath(UserSpecification, FALSE, FullNewDir);
if (!YoriLibUserStringToSingleFilePath(UserSpecification, FALSE, &LocalDir)) {
return FALSE;
}
}

//
// Check if the object exists. If it doesn't exist, free the string and
// say we successfully couldn't generate a match.
//

if (GetFileAttributes(FullNewDir->StartOfString) == (DWORD)-1) {
YoriLibFreeStringContents(FullNewDir);
if (GetFileAttributes(LocalDir.StartOfString) == (DWORD)-1) {
YoriLibFreeStringContents(&LocalDir);
}

memcpy(FullNewDir, &LocalDir, sizeof(YORI_STRING));
return TRUE;
}

Expand Down
3 changes: 2 additions & 1 deletion cal/cal.c
Expand Up @@ -565,7 +565,7 @@ ENTRYPOINT(
if (!YoriLibStringToNumber(&ArgV[StartArg], FALSE, &TargetYear, &CharsConsumed) ||
CharsConsumed == 0) {

YoriLibOutput(YORI_LIB_OUTPUT_STDERR, _T("cal: invalid year specified: %y\n"), &ArgV[StartArg]);
TargetYear = 0;
}

if (TargetYear > 0 && TargetYear <= sizeof(CalMonthNames)/sizeof(CalMonthNames[0])) {
Expand All @@ -576,6 +576,7 @@ ENTRYPOINT(

if (TargetYear < 1601 || TargetYear > 2100) {
YoriLibOutput(YORI_LIB_OUTPUT_STDERR, _T("cal: invalid year specified: %y\n"), &ArgV[StartArg]);
return EXIT_FAILURE;
}

CalOutputCalendarForYear((WORD)TargetYear, NULL);
Expand Down
43 changes: 31 additions & 12 deletions clip/clip.c
Expand Up @@ -109,6 +109,20 @@ static const CHAR DummyFragEnd[] =
*/
#define MAX_PIPE_SIZE (4*1024*1024)

//
// Older versions of the analysis engine don't understand that a buffer
// allocated with GlobalAlloc and subsequently locked with GlobalLock has
// the same writable size as specified in the call to GlobalAlloc. Since
// a generic overflow warning is useful, this is suppressed only for a
// couple of versions that have an analysis engine but can't interpret
// this condition.
//

#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (_MSC_VER <= 1600)
#pragma warning(push)
#pragma warning(disable: 6386)
#endif

/**
Copy the contents of a file or pipe to the clipboard in HTML format.
Expand Down Expand Up @@ -157,18 +171,19 @@ ClipCopyAsHtml(
// header.
//

YoriLibSPrintfA((PCHAR)pMem,
"Version:0.9\n"
"StartHTML:%08i\n"
"EndHTML:%08i\n"
"StartFragment:%08i\n"
"EndFragment:%08i\n"
"<!--StartFragment-->"
" ",
(int)HTMLCLIP_HDR_SIZE,
(int)(HTMLCLIP_HDR_SIZE + HTMLCLIP_FRAGSTART_SIZE + HTMLCLIP_FRAGEND_SIZE + 1 + FileSize),
(int)(HTMLCLIP_HDR_SIZE + HTMLCLIP_FRAGSTART_SIZE),
(int)(HTMLCLIP_HDR_SIZE + HTMLCLIP_FRAGSTART_SIZE + 1 + FileSize));
YoriLibSPrintfSA((PCHAR)pMem,
AllocSize,
"Version:0.9\n"
"StartHTML:%08i\n"
"EndHTML:%08i\n"
"StartFragment:%08i\n"
"EndFragment:%08i\n"
"<!--StartFragment-->"
" ",
(int)HTMLCLIP_HDR_SIZE,
(int)(HTMLCLIP_HDR_SIZE + HTMLCLIP_FRAGSTART_SIZE + HTMLCLIP_FRAGEND_SIZE + 1 + FileSize),
(int)(HTMLCLIP_HDR_SIZE + HTMLCLIP_FRAGSTART_SIZE),
(int)(HTMLCLIP_HDR_SIZE + HTMLCLIP_FRAGSTART_SIZE + 1 + FileSize));

CurrentOffset = 0;

Expand Down Expand Up @@ -430,6 +445,10 @@ ClipCopyAsRtf(
return TRUE;
}

#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (_MSC_VER <= 1600)
#pragma warning(pop)
#endif

/**
Copy the contents of a file or pipe to the clipboard in text format.
Expand Down
4 changes: 3 additions & 1 deletion co/co.c
Expand Up @@ -981,7 +981,9 @@ CoCreateSynchronousMenu(VOID)

}
Result = FALSE;
YoriWinProcessInputForWindow(Parent, &Result);
if (!YoriWinProcessInputForWindow(Parent, &Result)) {
Result = FALSE;
}

CoFreeContext(&CoContext);

Expand Down
17 changes: 17 additions & 0 deletions cpuinfo/cpuinfo.c
Expand Up @@ -181,6 +181,20 @@ CpuInfoExpandVariables(
return CharsNeeded;
}


//
// The CPUINFO_CONTEXT structure records a pointer to an array and the size
// of the array in bytes. Unfortunately I can't see a way to describe this
// relationship for older analyzers, so they believe accessing array elements
// is walking off the end of the buffer. Because this seems specific to
// older versions, the suppression is limited to those also.
//

#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (_MSC_VER <= 1600)
#pragma warning(push)
#pragma warning(disable: 6385)
#endif

/**
Parse the array of information about processor topologies and count the
number of elements in each.
Expand Down Expand Up @@ -422,6 +436,9 @@ CpuInfoDisplaySockets(
return TRUE;
}

#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (_MSC_VER <= 1600)
#pragma warning(pop)
#endif

/**
Load processor information from GetLogicalProcessorInformationEx.
Expand Down
23 changes: 23 additions & 0 deletions crt/ep_cons.c
Expand Up @@ -42,8 +42,22 @@
#pragma warning(disable: 26451) // Arithmetic overflow
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(push)
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#pragma warning(disable: 4668) // preprocessor conditional with nonexistent macro, SDK bug
#pragma warning(disable: 4255) // no function prototype given. 8.1 and earlier SDKs exhibit this.
#pragma warning(disable: 4820) // implicit padding added in structure
#endif

#include <windows.h>

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(pop)
#endif

/**
Indicate to the standard CRT header that we're compiling the CRT itself.
*/
Expand Down Expand Up @@ -166,6 +180,15 @@ mini_tcmdlinetoargs(LPTSTR szCmdLine, int * argc)
}
if (*c != '\0') {
arg_count++;
#if defined(_MSC_VER) && (_MSC_VER >= 1700)
//
// The 2013 analyzer thinks this could overrun, but doesn't
// provide much detail as to why. I think it can't follow
// that the logic above is the same as the logic below for
// calculating the argument and character count.
//
#pragma warning(suppress: 6386)
#endif
ret[arg_count] = ret_str;
}
} else {
Expand Down
16 changes: 15 additions & 1 deletion crt/ep_dll.c
Expand Up @@ -38,12 +38,26 @@
#pragma warning(disable: 4214) // bit field type other than int
#pragma warning(disable: 4514) // unreferenced inline function

#if defined(_MSC_VER) && (_MSC_VER <= 1500)
#if defined(_MSC_VER) && (_MSC_VER <= 1400)
#pragma warning(disable: 4705) // statement has no effect
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(push)
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#pragma warning(disable: 4668) // preprocessor conditional with nonexistent macro, SDK bug
#pragma warning(disable: 4255) // no function prototype given. 8.1 and earlier SDKs exhibit this.
#pragma warning(disable: 4820) // implicit padding added in structure
#endif

#include <windows.h>

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(pop)
#endif

/**
Indicate to the standard CRT header that we're compiling the CRT itself.
*/
Expand Down
16 changes: 15 additions & 1 deletion crt/mem.c
Expand Up @@ -38,12 +38,26 @@
#pragma warning(disable: 4214) // bit field type other than int
#pragma warning(disable: 4514) // unreferenced inline function

#if defined(_MSC_VER) && (_MSC_VER >= 1900)
#if defined(_MSC_VER) && (_MSC_VER >= 1910)
#pragma warning(disable: 5045) // spectre mitigation
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(push)
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#pragma warning(disable: 4668) // preprocessor conditional with nonexistent macro, SDK bug
#pragma warning(disable: 4255) // no function prototype given. 8.1 and earlier SDKs exhibit this.
#pragma warning(disable: 4820) // implicit padding added in structure
#endif

#include <windows.h>

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(pop)
#endif

/**
Indicate to the standard CRT header that we're compiling the CRT itself.
*/
Expand Down
14 changes: 14 additions & 0 deletions crt/rand.c
Expand Up @@ -38,8 +38,22 @@
#pragma warning(disable: 4214) // bit field type other than int
#pragma warning(disable: 4514) // unreferenced inline function

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(push)
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#pragma warning(disable: 4668) // preprocessor conditional with nonexistent macro, SDK bug
#pragma warning(disable: 4255) // no function prototype given. 8.1 and earlier SDKs exhibit this.
#pragma warning(disable: 4820) // implicit padding added in structure
#endif

#include <windows.h>

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(pop)
#endif

/**
Indicate to the standard CRT header that we're compiling the CRT itself.
*/
Expand Down
16 changes: 15 additions & 1 deletion crt/string.c
Expand Up @@ -38,12 +38,26 @@
#pragma warning(disable: 4214) // bit field type other than int
#pragma warning(disable: 4514) // unreferenced inline function

#if defined(_MSC_VER) && (_MSC_VER >= 1900)
#if defined(_MSC_VER) && (_MSC_VER >= 1910)
#pragma warning(disable: 5045) // spectre mitigation
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(push)
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#pragma warning(disable: 4668) // preprocessor conditional with nonexistent macro, SDK bug
#pragma warning(disable: 4255) // no function prototype given. 8.1 and earlier SDKs exhibit this.
#pragma warning(disable: 4820) // implicit padding added in structure
#endif

#include <windows.h>

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma warning(pop)
#endif

/**
Indicate to the standard CRT header that we're compiling the CRT itself.
*/
Expand Down
4 changes: 2 additions & 2 deletions cvtvt/main.c
Expand Up @@ -411,8 +411,8 @@ ENTRYPOINT(
// Here we "know" the thread is very simple, holds no locks, does
// no cleanup of its own, etc.
//
#if defined(_MSC_VER) && (_MSC_VER >= 1700)
#pragma warning(suppress: 6258)
#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#pragma warning(disable: 6258)
#endif
TerminateThread(InputPumpThread, 0);
CloseHandle(InputPumpThread);
Expand Down
8 changes: 6 additions & 2 deletions date/date.c
Expand Up @@ -150,13 +150,17 @@ DateExpandVariables(
} else if (YoriLibCompareStringWithLiteral(VariableName, _T("ms")) == 0) {
CharsNeeded = 4;
} else if (YoriLibCompareStringWithLiteral(VariableName, _T("COUNT_MS")) == 0) {
SystemTimeToFileTime(&DateContext->Time, &Clock);
if (!SystemTimeToFileTime(&DateContext->Time, &Clock)) {
return 0;
}
liClock.HighPart = Clock.dwHighDateTime;
liClock.LowPart = Clock.dwLowDateTime;
liClock.QuadPart = liClock.QuadPart / 10000;
CharsNeeded = YoriLibSPrintfSize(_T("%016lli"), liClock.QuadPart);
} else if (YoriLibCompareStringWithLiteral(VariableName, _T("count_ms")) == 0) {
SystemTimeToFileTime(&DateContext->Time, &Clock);
if (!SystemTimeToFileTime(&DateContext->Time, &Clock)) {
return 0;
}
liClock.HighPart = Clock.dwHighDateTime;
liClock.LowPart = Clock.dwLowDateTime;
liClock.QuadPart = liClock.QuadPart / 10000;
Expand Down

0 comments on commit bd29c9d

Please sign in to comment.