Skip to content

Commit 7ffb284

Browse files
committed
[LINT] error 732
Loss of sign (Context) (Type to Type) This mostly consists of a change to unsigned integers for any values pertaining to sizes and indices. Sizes have been changed to size_t and indices to idx_t (newly defined in stdafx.h). However, the changes are rather invasive and I'm not 100% about their added values. Should the maintainer of the project feel this commit isn't worthy of the project, I'd understand if it's cherry picked out of the mainline branch. Signed-off-by: Jocelyn Legault <jocelynlegault@gmail.com>
1 parent f579351 commit 7ffb284

28 files changed

Lines changed: 226 additions & 216 deletions

PythonScript/src/ConfigFile.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,9 @@ const tstring& ConfigFile::getSetting(const TCHAR *settingName)
147147
return m_settings[tstring(settingName)];
148148
}
149149

150-
151-
const std::string& ConfigFile::getMenuScript(int index) const
150+
const std::string& ConfigFile::getMenuScript(idx_t index) const
152151
{
153-
if (m_menuScripts.size() > static_cast<size_t>(index))
152+
if (m_menuScripts.size() > index)
154153
{
155154
return m_menuScripts[index];
156155
}

PythonScript/src/ConfigFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ConfigFile
1919
// TODO: Need to make these pointers
2020
MenuItemsTD getMenuItems() { return m_menuItems; };
2121
ToolbarItemsTD getToolbarItems() { return m_toolbarItems; };
22-
const std::string& getMenuScript(int index) const;
22+
const std::string& getMenuScript(idx_t index) const;
2323

2424
void addMenuItem(const tstring scriptPath);
2525
void addToolbarItem(const tstring scriptPath, const tstring iconPath);

PythonScript/src/ConsoleDialog.cpp

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ BOOL CALLBACK ConsoleDialog::run_dlgProc(HWND hWnd, UINT message, WPARAM wParam,
113113

114114
SetMenuItemInfo(m_hContext, 2, FALSE, &mi);
115115

116-
UINT cmdID = TrackPopupMenu(m_hContext, TPM_RETURNCMD, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0, _hSelf, NULL);
116+
// Thanks MS for corrupting the value of BOOL. :-/
117+
// From the documentation (http://msdn.microsoft.com/en-us/library/ms648002.aspx):
118+
//
119+
// If you specify TPM_RETURNCMD in the uFlags parameter, the return value is the menu-item
120+
// identifier of the item that the user selected. If the user cancels the menu without making
121+
// a selection, or if an error occurs, then the return value is zero.
122+
INT cmdID = (INT)TrackPopupMenu(m_hContext, TPM_RETURNCMD, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0, _hSelf, NULL);
117123

118124
switch(cmdID)
119125
{
@@ -220,7 +226,6 @@ void ConsoleDialog::historyPrevious()
220226
::SetWindowTextA(m_hInput, m_changes[m_currentHistory].c_str());
221227
::SendMessage(m_hInput, EM_SETSEL, m_changes[m_currentHistory].size(), m_changes[m_currentHistory].size());
222228
}
223-
224229
}
225230
}
226231

@@ -266,9 +271,7 @@ void ConsoleDialog::historyNext()
266271
// Set it as the changed string
267272
::SetWindowTextA(m_hInput, m_changes[m_currentHistory].c_str());
268273
::SendMessage(m_hInput, EM_SETSEL, m_changes[m_currentHistory].size(), m_changes[m_currentHistory].size());
269-
270274
}
271-
272275
}
273276
}
274277

@@ -430,10 +433,10 @@ void ConsoleDialog::createOutputWindow(HWND hParentWindow)
430433
callScintilla(SCI_SETLEXER, SCLEX_CONTAINER);
431434
}
432435

433-
void ConsoleDialog::writeText(int length, const char *text)
436+
void ConsoleDialog::writeText(size_t length, const char *text)
434437
{
435438
::SendMessage(m_scintilla, SCI_SETREADONLY, 0, 0);
436-
for (int i = 0; i < length; ++i)
439+
for (idx_t i = 0; i < length; ++i)
437440
{
438441
if (text[i] == '\r')
439442
{
@@ -456,12 +459,12 @@ void ConsoleDialog::writeText(int length, const char *text)
456459
}
457460

458461

459-
void ConsoleDialog::writeError(int length, const char *text)
462+
void ConsoleDialog::writeError(size_t length, const char *text)
460463
{
461464
int docLength = callScintilla(SCI_GETLENGTH);
462465
int realLength = length;
463466
callScintilla(SCI_SETREADONLY, 0);
464-
for (int i = 0; i < length; ++i)
467+
for (idx_t i = 0; i < length; ++i)
465468
{
466469
if (text[i] == '\r')
467470
{
@@ -564,9 +567,9 @@ void ConsoleDialog::onStyleNeeded(SCNotification* notification)
564567
LineDetails lineDetails;
565568
for(int lineNumber = startLine; lineNumber <= endLine; ++lineNumber)
566569
{
567-
lineDetails.lineLength = callScintilla(SCI_GETLINE, lineNumber);
570+
lineDetails.lineLength = (size_t)callScintilla(SCI_GETLINE, lineNumber);
568571

569-
if (lineDetails.lineLength > 0)
572+
if (lineDetails.lineLength != SIZE_MAX)
570573
{
571574
lineDetails.line = new char[lineDetails.lineLength + 1];
572575
callScintilla(SCI_GETLINE, lineNumber, reinterpret_cast<LPARAM>(lineDetails.line));
@@ -675,8 +678,8 @@ bool ConsoleDialog::parseVSErrorLine(LineDetails *lineDetails)
675678
bool retVal = false;
676679
styleState = SS_BEGIN;
677680

678-
int pos = 0;
679-
lineDetails->errorLineNo = -1;
681+
idx_t pos = 0;
682+
lineDetails->errorLineNo = IDX_MAX;
680683

681684
while (styleState != SS_EXIT)
682685
{
@@ -725,8 +728,8 @@ bool ConsoleDialog::parseVSErrorLine(LineDetails *lineDetails)
725728

726729
case SS_LINENUMBER:
727730
{
728-
int startLineNoPos = pos;
729-
int endLineNoPos;
731+
idx_t startLineNoPos = pos;
732+
idx_t endLineNoPos;
730733
while(lineDetails->line[pos] >= '0' && lineDetails->line[pos] <= '9' && pos < lineDetails->lineLength)
731734
{
732735
++pos;
@@ -757,7 +760,7 @@ bool ConsoleDialog::parseVSErrorLine(LineDetails *lineDetails)
757760

758761
char *lineNumber = new char[endLineNoPos - startLineNoPos + 2];
759762
strncpy_s(lineNumber, endLineNoPos - startLineNoPos + 2, lineDetails->line + startLineNoPos, endLineNoPos - startLineNoPos);
760-
lineDetails->errorLineNo = atoi(lineNumber) - 1;
763+
lineDetails->errorLineNo = strtoul(lineNumber, NULL, 0) - 1;
761764
delete[] lineNumber;
762765
lineDetails->filenameEnd = startLineNoPos - 1;
763766
retVal = true;
@@ -809,9 +812,9 @@ bool ConsoleDialog::parseGCCErrorLine(LineDetails *lineDetails)
809812
bool retVal = false;
810813
styleState = SS_FILENAME;
811814

812-
int pos = 0;
815+
idx_t pos = 0;
813816
lineDetails->filenameStart = 0;
814-
lineDetails->errorLineNo = -1;
817+
lineDetails->errorLineNo = IDX_MAX;
815818

816819
while (styleState != SS_EXIT)
817820
{
@@ -861,15 +864,15 @@ bool ConsoleDialog::parseGCCErrorLine(LineDetails *lineDetails)
861864

862865
case SS_LINENUMBER:
863866
{
864-
int startLineNoPos = pos;
867+
idx_t startLineNoPos = pos;
865868
while(lineDetails->line[pos] >= '0' && lineDetails->line[pos] <= '9' && pos < lineDetails->lineLength)
866869
{
867870
++pos;
868871
}
869872
if (pos < (lineDetails->lineLength + 1)
870873
&& lineDetails->line[pos] == ':')
871874
{
872-
lineDetails->errorLineNo = atoi(lineDetails->line + startLineNoPos) - 1;
875+
lineDetails->errorLineNo = strtoul(lineDetails->line + startLineNoPos, NULL, 0) - 1;
873876

874877
// If the line number came out as 0, ie. there wasn't any,
875878
// then the line is not a gcc error
@@ -929,8 +932,8 @@ bool ConsoleDialog::parsePythonErrorLine(LineDetails *lineDetails)
929932

930933
bool retVal = false;
931934
styleState = SS_BEGIN;
932-
lineDetails->errorLineNo = -1;
933-
int pos = 0;
935+
lineDetails->errorLineNo = IDX_MAX;
936+
idx_t pos = 0;
934937
while(styleState != SS_EXIT)
935938
{
936939
switch(styleState)
@@ -979,7 +982,7 @@ bool ConsoleDialog::parsePythonErrorLine(LineDetails *lineDetails)
979982
break;
980983

981984
case SS_LINENUMBER:
982-
lineDetails->errorLineNo = atoi(lineDetails->line + pos) - 1;
985+
lineDetails->errorLineNo = strtoul(lineDetails->line + pos, NULL, 0) - 1;
983986
styleState = SS_EXIT;
984987
break;
985988

@@ -992,29 +995,21 @@ bool ConsoleDialog::parsePythonErrorLine(LineDetails *lineDetails)
992995
return retVal;
993996
}
994997

995-
996-
997-
998-
999-
1000-
1001998
void ConsoleDialog::onHotspotClick(SCNotification* notification)
1002999
{
1003-
10041000
int lineNumber = callScintilla(SCI_LINEFROMPOSITION, notification->position);
10051001
LineDetails lineDetails;
1006-
lineDetails.lineLength = callScintilla(SCI_GETLINE, lineNumber);
1002+
lineDetails.lineLength = (size_t)callScintilla(SCI_GETLINE, lineNumber);
10071003

1008-
if (lineDetails.lineLength > 0)
1004+
if (lineDetails.lineLength != SIZE_MAX)
1005+
{
1006+
lineDetails.line = new char[lineDetails.lineLength + 1];
1007+
callScintilla(SCI_GETLINE, lineNumber, reinterpret_cast<LPARAM>(lineDetails.line));
1008+
lineDetails.line[lineDetails.lineLength] = '\0';
1009+
if (parseLine(&lineDetails))
10091010
{
1010-
lineDetails.line = new char[lineDetails.lineLength + 1];
1011-
callScintilla(SCI_GETLINE, lineNumber, reinterpret_cast<LPARAM>(lineDetails.line));
1012-
lineDetails.line[lineDetails.lineLength] = '\0';
1013-
if (parseLine(&lineDetails))
1014-
{
1015-
lineDetails.line[lineDetails.filenameEnd] = '\0';
1016-
m_console->openFile(lineDetails.line + lineDetails.filenameStart, lineDetails.errorLineNo);
1017-
}
1011+
lineDetails.line[lineDetails.filenameEnd] = '\0';
1012+
m_console->openFile(lineDetails.line + lineDetails.filenameStart, lineDetails.errorLineNo);
10181013
}
1019-
1014+
}
10201015
}

PythonScript/src/ConsoleDialog.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class ConsoleDialog : public DockingDlgInterface
2222
void doDialog();
2323
void hide();
2424

25-
void writeText(int length, const char *text);
26-
void writeError(int length, const char *text);
25+
void writeText(size_t length, const char *text);
26+
void writeError(size_t length, const char *text);
2727
void clearText();
2828
void setPrompt(const char *prompt);
2929
HWND getScintillaHwnd() { return m_scintilla; };
@@ -91,10 +91,10 @@ struct LineDetails
9191
{
9292
public:
9393
char *line;
94-
int lineLength;
95-
int errorLineNo;
96-
int filenameStart;
97-
int filenameEnd;
94+
size_t lineLength;
95+
idx_t errorLineNo;
96+
idx_t filenameStart;
97+
idx_t filenameEnd;
9898
ErrorLevel errorLevel;
9999
};
100100

PythonScript/src/CreateWrapper.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def cellsBody(v, out):
9191

9292
def constString(v, out):
9393
out.write("\tconst char *raw = boost::python::extract<const char *>(" + v["Param2Name"] + ".attr(\"__str__\")());\n")
94-
out.write("\treturn callScintilla(" + symbolName(v) + ", len(" + v["Param2Name"] + "), reinterpret_cast<LPARAM>(raw));\n");
94+
out.write("\treturn callScintilla(" + symbolName(v) + ", _len(" + v["Param2Name"] + "), reinterpret_cast<LPARAM>(raw));\n");
9595

9696
def retString(v, out):
9797
out.write("\tPythonCompatibleStrBuffer result(callScintilla(" + symbolName(v) + ") + 1);\n")
@@ -175,7 +175,7 @@ def getStyledTextBody(v, out):
175175
out.write('\tcallScintilla({0}, 0, reinterpret_cast<LPARAM>(&src));\n'.format(symbolName(v)))
176176
out.write('\tboost::python::list styles;\n')
177177
out.write("\tPythonCompatibleStrBuffer result((end-start) + 1);\n")
178-
out.write('\tfor(int pos = 0; pos < result.size() - 1; pos++)\n')
178+
out.write('\tfor(idx_t pos = 0; pos < result.size() - 1; pos++)\n')
179179
out.write('\t{\n')
180180
out.write('\t\t(*result)[pos] = src.lpstrText[pos * 2];\n')
181181
out.write('\t\tstyles.append((int)(src.lpstrText[(pos * 2) + 1]));\n')
@@ -296,20 +296,26 @@ def writeCppFile(f,out):
296296
out.write('class PythonCompatibleStrBuffer\n')
297297
out.write('{\n')
298298
out.write('public:\n')
299+
out.write('\tinline explicit PythonCompatibleStrBuffer(size_t length) :\n')
300+
out.write('\t\tm_bufferLen(length),\n')
301+
out.write('\t\tm_bufferPtr(new char[m_bufferLen])\n')
302+
out.write('\t{\n')
303+
out.write('\t\tif (m_bufferPtr && m_bufferLen > 0) m_bufferPtr[m_bufferLen-1] = \'\\0\';\n')
304+
out.write('\t}\n')
299305
out.write('\tinline PythonCompatibleStrBuffer(int length) :\n')
300-
out.write('\t\tm_bufferPtr(new char[length]),\n')
301-
out.write('\t\tm_bufferLen(length)\n')
306+
out.write('\t\tm_bufferLen(length>=0?(size_t)length:0),\n')
307+
out.write('\t\tm_bufferPtr(new char[m_bufferLen])\n')
302308
out.write('\t{\n')
303-
out.write('\t\tm_bufferPtr[length-1] = \'\\0\';\n')
309+
out.write('\t\tif (m_bufferPtr && m_bufferLen > 0) m_bufferPtr[m_bufferLen-1] = \'\\0\';\n')
304310
out.write('\t}\n')
305311
out.write('\tinline ~PythonCompatibleStrBuffer() { delete [] m_bufferPtr; }\n')
306312
out.write('\tinline char* operator*() const { return m_bufferPtr; }\n')
307313
out.write('\tinline const char* c_str() const { return m_bufferPtr; }\n')
308-
out.write('\tinline int size() const { return m_bufferLen; }\n')
314+
out.write('\tinline size_t size() const { return m_bufferLen; }\n')
309315
out.write('private:\n')
310316
out.write('\tPythonCompatibleStrBuffer(); // default constructor disabled\n')
317+
out.write('\tsize_t m_bufferLen;\n')
311318
out.write('\tchar* m_bufferPtr;\n')
312-
out.write('\tint m_bufferLen;\n')
313319
out.write('};\n')
314320
out.write('\n')
315321

PythonScript/src/DynamicIDManager.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@
44
#include "DynamicIDManager.h"
55
#include "IDAllocator.h"
66

7-
void DynamicIDManager::reserve(int quantity)
7+
void DynamicIDManager::reserve( size_t quantity )
88
{
99
if (quantity > m_capacity)
1010
{
1111
reserveAdditional(quantity - m_capacity);
1212
}
1313
}
1414

15-
void DynamicIDManager::addBlock(int start, int quantity)
15+
void DynamicIDManager::addBlock( idx_t start, size_t quantity )
1616
{
17-
m_idList.push_back(std::pair<int, int>(start, quantity));
17+
m_idList.push_back(t_id(start, quantity));
1818

1919
// Assume no overlaps (should really fix this, but we just need to use this carefully)
2020
m_capacity += quantity;
2121
}
2222

23-
void DynamicIDManager::reserveAdditional(int quantity)
23+
void DynamicIDManager::reserveAdditional( size_t quantity )
2424
{
25-
26-
int start;
25+
idx_t start;
2726
if (allocateIDs(quantity, &start))
2827
{
2928
t_idList::reverse_iterator iter = m_idList.rbegin();
@@ -39,15 +38,15 @@ void DynamicIDManager::reserveAdditional(int quantity)
3938

4039
else // Otherwise just add a new block
4140
{
42-
m_idList.push_back(std::pair<int, int>(start, quantity));
41+
m_idList.push_back(t_id(start, quantity));
4342
}
4443

4544
m_capacity += quantity;
4645
}
4746
}
4847

4948

50-
int DynamicIDManager::begin()
49+
idx_t DynamicIDManager::begin()
5150
{
5251
m_current = m_idList.begin();
5352
if (m_current == m_idList.end())
@@ -64,7 +63,7 @@ int DynamicIDManager::begin()
6463
return m_nextID;
6564
}
6665

67-
int DynamicIDManager::currentID()
66+
idx_t DynamicIDManager::currentID()
6867
{
6968
return m_nextID;
7069
}
@@ -119,16 +118,16 @@ DynamicIDManager& DynamicIDManager::operator++(int)
119118
}
120119

121120

122-
bool DynamicIDManager::allocateIDs(int quantity, int *start)
121+
bool DynamicIDManager::allocateIDs(size_t quantity, idx_t *start)
123122
{
124123
return m_allocator->allocate(quantity, start);
125124
}
126125

127126

128-
bool DynamicIDManager::inRange(int id)
127+
bool DynamicIDManager::inRange(idx_t id)
129128
{
130129
bool retVal = false;
131-
std::list< std::pair<int, int> >::iterator it = m_idList.begin();
130+
t_idList::iterator it = m_idList.begin();
132131
for(;it != m_idList.end(); ++it)
133132
{
134133
if (it->first > id)

0 commit comments

Comments
 (0)