Skip to content

Commit d4a73d2

Browse files
committed
- added [[fallthrough]] annotation
- changed spaces -> tabs - added nullpointer check - init pointers
1 parent 11774d6 commit d4a73d2

File tree

5 files changed

+227
-223
lines changed

5 files changed

+227
-223
lines changed

PythonScript/src/ConfigFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void ConfigFile::readConfig()
6464
{
6565
tstring scriptFullPath = _T("");
6666
startupFile.getline(buffer, 500);
67-
char *context;
67+
char *context = nullptr;
6868
char *element = strtok_s(buffer, "/", &context);
6969
if (element)
7070
{

PythonScript/src/DebugTrace.cpp

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,66 @@
1010
#include <Windows.h>
1111
#include <DbgHelp.h>
1212

13-
// stati volatile long s_debugLineCount;
13+
// static volatile long s_debugLineCount;
1414

1515

1616

1717
volatile long *allocateLineCount()
1818
{
19-
static volatile long *lineCount;
19+
static volatile long *lineCount;
2020

21-
lineCount = (long*)_aligned_malloc(sizeof(long), 32);
22-
*lineCount = 0;
23-
return lineCount;
21+
lineCount = (long*)_aligned_malloc(sizeof(long), 32);
22+
*lineCount = 0;
23+
return lineCount;
2424
}
2525

2626
void printStack()
2727
{
28-
unsigned int i;
29-
void * stack[ 100 ];
30-
unsigned short frames;
31-
SYMBOL_INFO * symbol;
32-
HANDLE process;
33-
char buffer[500]{};
34-
int bufferRemaining = 500;
35-
int usedBuffer;
36-
char *output = buffer;
37-
38-
process = GetCurrentProcess();
39-
40-
SymInitialize( process, NULL, TRUE );
41-
42-
frames = CaptureStackBackTrace( 1, 15, stack, NULL );
43-
symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 );
44-
symbol->MaxNameLen = 255;
45-
symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
46-
47-
48-
for( i = 0; i < frames; i++ )
49-
{
50-
SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
51-
52-
usedBuffer = _snprintf_s(output, bufferRemaining, bufferRemaining, "%i: %s - 0x%I64X\n", frames - i - 1, symbol->Name, symbol->Address );
53-
bufferRemaining -= usedBuffer;
54-
output += usedBuffer;
55-
}
56-
57-
debugTraceVars("STACK %s", buffer);
58-
59-
free( symbol );
28+
unsigned int i;
29+
void * stack[ 100 ];
30+
unsigned short frames;
31+
SYMBOL_INFO * symbol;
32+
HANDLE process;
33+
char buffer[500]{};
34+
int bufferRemaining = 500;
35+
int usedBuffer;
36+
char *output = buffer;
37+
38+
process = GetCurrentProcess();
39+
40+
SymInitialize( process, NULL, TRUE );
41+
42+
frames = CaptureStackBackTrace( 1, 15, stack, NULL );
43+
symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 );
44+
symbol->MaxNameLen = 255;
45+
symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
46+
47+
48+
for( i = 0; i < frames; i++ )
49+
{
50+
SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
51+
52+
usedBuffer = _snprintf_s(output, bufferRemaining, bufferRemaining, "%i: %s - 0x%I64X\n", frames - i - 1, symbol->Name, symbol->Address );
53+
bufferRemaining -= usedBuffer;
54+
output += usedBuffer;
55+
}
56+
57+
debugTraceVars("STACK %s", buffer);
58+
59+
free( symbol );
6060
}
6161

6262
void debugTraceStr(const std::wstringstream& item)
6363
{
64-
static volatile long *lineCount = allocateLineCount();
65-
FILETIME timestamp;
66-
GetSystemTimeAsFileTime(&timestamp);
64+
static volatile long *lineCount = allocateLineCount();
65+
FILETIME timestamp;
66+
GetSystemTimeAsFileTime(&timestamp);
6767

68-
69-
long currentLine = InterlockedIncrement(lineCount);
70-
std::wstringstream debug;
68+
69+
long currentLine = InterlockedIncrement(lineCount);
70+
std::wstringstream debug;
7171
debug << L"PY>" << std::setfill(L'0') << std::setw(5) << ::GetCurrentThreadId()
72-
<< L" " << std::setw(5) << std::setfill(L' ') << currentLine
72+
<< L" " << std::setw(5) << std::setfill(L' ') << currentLine
7373
<< L" " << std::setw(8) << std::setfill(L' ') << timestamp.dwLowDateTime
7474
<< L" " << item.str();
7575

@@ -78,13 +78,13 @@ void debugTraceStr(const std::wstringstream& item)
7878

7979
void debugTraceVars(const char *format, ...)
8080
{
81-
va_list args;
82-
va_start( args, format );
83-
char buffer[500];
84-
vsprintf_s<500>(buffer, format, args);
85-
std::wstringstream result;
81+
va_list args;
82+
va_start( args, format );
83+
char buffer[500];
84+
vsprintf_s<500>(buffer, format, args);
85+
std::wstringstream result;
8686
result << buffer;
87-
debugTraceStr(result);
87+
debugTraceStr(result);
8888
}
8989

9090

PythonScript/src/PythonScript.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *nbF)
147147
{
148148
MessageBox(NULL, _T("A fatal error has occurred. Notepad++ has incorrectly called getFuncsArray() before setInfo(). No menu items will be available for PythonScript."), PLUGIN_NAME, 0);
149149
funcItem = (FuncItem*) malloc(sizeof(FuncItem));
150-
memset(funcItem, 0, sizeof(FuncItem));
151-
_tcscpy_s(funcItem[0]._itemName, 64, _T("About - Python Script Disabled"));
152-
funcItem[0]._pFunc = doAbout;
150+
if(funcItem)
151+
{
152+
memset(funcItem, 0, sizeof(FuncItem));
153+
_tcscpy_s(funcItem[0]._itemName, 64, _T("About - Python Script Disabled"));
154+
funcItem[0]._pFunc = doAbout;
155+
}
153156
*nbF = 1;
154157
}
155158

0 commit comments

Comments
 (0)