88#include " PluginInterface.h"
99#include " Docking.h"
1010
11- ConsoleDialog::ConsoleDialog ()
12- : DockingDlgInterface(IDD_CONSOLE),
11+ ConsoleDialog::ConsoleDialog () :
12+ DockingDlgInterface(IDD_CONSOLE),
1313 m_data(new tTbData),
14- m_prompt(" >>> " ),
1514 m_scintilla(NULL ),
1615 m_hInput(NULL ),
1716 m_console(NULL ),
17+ m_prompt(" >>> " ),
1818 m_originalInputWndProc(NULL ),
1919 m_hTabIcon(NULL ),
2020 m_currentHistory(0 ),
@@ -24,6 +24,28 @@ ConsoleDialog::ConsoleDialog()
2424 m_historyIter = m_history.end ();
2525}
2626
27+ // lint -e1554 Direct pointer copy of member 'name' within copy constructor: 'ConsoleDialog::ConsoleDialog(const ConsoleDialog &)')
28+ // We indeed copy pointers, and it's okay. These are not allocated within the
29+ // scope of this class but rather passed in and copied anyway.
30+ ConsoleDialog::ConsoleDialog (const ConsoleDialog& other) :
31+ DockingDlgInterface(other),
32+ m_data(other.m_data ? new tTbData(*other.m_data) : NULL),
33+ m_scintilla(other.m_scintilla),
34+ m_hInput(other.m_hInput),
35+ m_console(other.m_console),
36+ m_prompt(other.m_prompt),
37+ m_originalInputWndProc(NULL ),
38+ m_hTabIcon(NULL ),
39+ m_history(other.m_history),
40+ m_historyIter(other.m_historyIter),
41+ m_changes(other.m_changes),
42+ m_currentHistory(other.m_currentHistory),
43+ m_runButtonIsRun(other.m_runButtonIsRun),
44+ m_hContext(NULL )
45+ {
46+ }
47+ // lint +e1554
48+
2749ConsoleDialog::~ConsoleDialog ()
2850{
2951 if (m_scintilla)
@@ -35,7 +57,25 @@ ConsoleDialog::~ConsoleDialog()
3557 if (m_data)
3658 {
3759 delete m_data;
60+ m_data = NULL ;
61+ }
62+
63+ if (m_hTabIcon)
64+ {
65+ ::DestroyIcon (m_hTabIcon);
66+ m_hTabIcon = NULL ;
67+ }
68+
69+ if (m_hContext)
70+ {
71+ ::DestroyMenu (m_hContext);
72+ m_hContext = NULL ;
3873 }
74+
75+ // To please Lint, let's NULL these handles and pointers
76+ m_hInput = NULL ;
77+ m_console = NULL ;
78+
3979}
4080
4181
@@ -113,7 +153,13 @@ BOOL CALLBACK ConsoleDialog::run_dlgProc(HWND hWnd, UINT message, WPARAM wParam,
113153
114154 SetMenuItemInfo (m_hContext, 2 , FALSE , &mi);
115155
116- UINT cmdID = TrackPopupMenu (m_hContext, TPM_RETURNCMD, GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), 0 , _hSelf, NULL );
156+ // Thanks MS for corrupting the value of BOOL. :-/
157+ // From the documentation (http://msdn.microsoft.com/en-us/library/ms648002.aspx):
158+ //
159+ // If you specify TPM_RETURNCMD in the uFlags parameter, the return value is the menu-item
160+ // identifier of the item that the user selected. If the user cancels the menu without making
161+ // a selection, or if an error occurs, then the return value is zero.
162+ INT cmdID = (INT)TrackPopupMenu (m_hContext, TPM_RETURNCMD, GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), 0 , _hSelf, NULL );
117163
118164 switch (cmdID)
119165 {
@@ -212,15 +258,14 @@ void ConsoleDialog::historyPrevious()
212258 if (m_changes.find (m_currentHistory) == m_changes.end ())
213259 {
214260 ::SetWindowTextA (m_hInput, m_historyIter->c_str ());
215- ::SendMessage (m_hInput, EM_SETSEL, m_historyIter->size (), m_historyIter->size());
261+ ::SendMessage (m_hInput, EM_SETSEL, m_historyIter->size (), (LPARAM) m_historyIter->size());
216262 }
217263 else
218264 {
219265 // Set it as the changed string
220266 ::SetWindowTextA (m_hInput, m_changes[m_currentHistory].c_str());
221- ::SendMessage (m_hInput, EM_SETSEL, m_changes[m_currentHistory].size(), m_changes[m_currentHistory].size());
267+ ::SendMessage (m_hInput, EM_SETSEL, m_changes[m_currentHistory].size(), (LPARAM) m_changes[m_currentHistory].size());
222268 }
223-
224269 }
225270}
226271
@@ -254,7 +299,7 @@ void ConsoleDialog::historyNext()
254299 if (m_historyIter != m_history.end ())
255300 {
256301 ::SetWindowTextA (m_hInput, m_historyIter->c_str ());
257- ::SendMessage (m_hInput, EM_SETSEL, m_historyIter->size (), m_historyIter->size());
302+ ::SendMessage (m_hInput, EM_SETSEL, m_historyIter->size (), (LPARAM) m_historyIter->size());
258303 }
259304 else
260305 {
@@ -265,10 +310,8 @@ void ConsoleDialog::historyNext()
265310 {
266311 // Set it as the changed string
267312 ::SetWindowTextA (m_hInput, m_changes[m_currentHistory].c_str());
268- ::SendMessage (m_hInput, EM_SETSEL, m_changes[m_currentHistory].size(), m_changes[m_currentHistory].size());
269-
313+ ::SendMessage (m_hInput, EM_SETSEL, m_changes[m_currentHistory].size(), (LPARAM)m_changes[m_currentHistory].size());
270314 }
271-
272315 }
273316}
274317
@@ -430,10 +473,10 @@ void ConsoleDialog::createOutputWindow(HWND hParentWindow)
430473 callScintilla (SCI_SETLEXER, SCLEX_CONTAINER);
431474}
432475
433- void ConsoleDialog::writeText (int length, const char *text)
476+ void ConsoleDialog::writeText (size_t length, const char *text)
434477{
435478 ::SendMessage (m_scintilla, SCI_SETREADONLY, 0 , 0 );
436- for (int i = 0 ; i < length; ++i)
479+ for (idx_t i = 0 ; i < length; ++i)
437480 {
438481 if (text[i] == ' \r ' )
439482 {
@@ -456,12 +499,12 @@ void ConsoleDialog::writeText(int length, const char *text)
456499}
457500
458501
459- void ConsoleDialog::writeError (int length, const char *text)
502+ void ConsoleDialog::writeError (size_t length, const char *text)
460503{
461- int docLength = callScintilla (SCI_GETLENGTH);
462- int realLength = length;
504+ size_t docLength = ( size_t ) callScintilla (SCI_GETLENGTH);
505+ size_t realLength = length;
463506 callScintilla (SCI_SETREADONLY, 0 );
464- for (int i = 0 ; i < length; ++i)
507+ for (idx_t i = 0 ; i < length; ++i)
465508 {
466509 if (text[i] == ' \r ' )
467510 {
@@ -497,6 +540,9 @@ void ConsoleDialog::doDialog()
497540 {
498541 create (m_data);
499542
543+ assert (m_data);
544+ if (m_data)
545+ {
500546 // define the default docking behaviour
501547 m_data->uMask = DWS_DF_CONT_BOTTOM | DWS_ICONTAB;
502548 m_data->pszName = new TCHAR[20 ];
@@ -522,6 +568,7 @@ void ConsoleDialog::doDialog()
522568 // Parse the whole doc, in case we've had errors that haven't been parsed yet
523569 callScintilla (SCI_COLOURISE, 0 , -1 );
524570 }
571+ }
525572
526573 display (true );
527574}
@@ -555,16 +602,16 @@ void ConsoleDialog::clearText()
555602
556603void ConsoleDialog::onStyleNeeded (SCNotification* notification)
557604{
558- int startPos = callScintilla (SCI_GETENDSTYLED);
559- int startLine = callScintilla (SCI_LINEFROMPOSITION, startPos);
560- int endPos = notification->position ;
561- int endLine = callScintilla (SCI_LINEFROMPOSITION, endPos);
605+ idx_t startPos = ( idx_t ) callScintilla (SCI_GETENDSTYLED);
606+ idx_t startLine = ( idx_t ) callScintilla (SCI_LINEFROMPOSITION, startPos);
607+ idx_t endPos = ( idx_t ) notification->position ;
608+ idx_t endLine = ( idx_t ) callScintilla (SCI_LINEFROMPOSITION, endPos);
562609
563610
564611 LineDetails lineDetails;
565- for (int lineNumber = startLine; lineNumber <= endLine; ++lineNumber)
612+ for (idx_t lineNumber = startLine; lineNumber <= endLine; ++lineNumber)
566613 {
567- lineDetails.lineLength = callScintilla (SCI_GETLINE, lineNumber);
614+ lineDetails.lineLength = ( size_t ) callScintilla (SCI_GETLINE, lineNumber);
568615
569616 if (lineDetails.lineLength > 0 )
570617 {
@@ -576,7 +623,7 @@ void ConsoleDialog::onStyleNeeded(SCNotification* notification)
576623
577624 if (parseLine (&lineDetails))
578625 {
579- startPos = callScintilla (SCI_POSITIONFROMLINE, lineNumber);
626+ startPos = ( idx_t ) callScintilla (SCI_POSITIONFROMLINE, lineNumber);
580627
581628 // Check that it's not just a file called '<console>'
582629 if (strncmp (lineDetails.line + lineDetails.filenameStart , " <console>" , lineDetails.filenameEnd - lineDetails.filenameStart ))
@@ -675,8 +722,8 @@ bool ConsoleDialog::parseVSErrorLine(LineDetails *lineDetails)
675722 bool retVal = false ;
676723 styleState = SS_BEGIN;
677724
678- int pos = 0 ;
679- lineDetails->errorLineNo = - 1 ;
725+ idx_t pos = 0 ;
726+ lineDetails->errorLineNo = IDX_MAX ;
680727
681728 while (styleState != SS_EXIT)
682729 {
@@ -725,8 +772,8 @@ bool ConsoleDialog::parseVSErrorLine(LineDetails *lineDetails)
725772
726773 case SS_LINENUMBER:
727774 {
728- int startLineNoPos = pos;
729- int endLineNoPos;
775+ idx_t startLineNoPos = pos;
776+ idx_t endLineNoPos;
730777 while (lineDetails->line [pos] >= ' 0' && lineDetails->line [pos] <= ' 9' && pos < lineDetails->lineLength )
731778 {
732779 ++pos;
@@ -755,9 +802,9 @@ bool ConsoleDialog::parseVSErrorLine(LineDetails *lineDetails)
755802 break ;
756803 }
757804
758- char *lineNumber = new char [endLineNoPos - startLineNoPos + 2 ];
759- strncpy_s (lineNumber, endLineNoPos - startLineNoPos + 2 , lineDetails->line + startLineNoPos, endLineNoPos - startLineNoPos);
760- lineDetails->errorLineNo = atoi (lineNumber) - 1 ;
805+ char *lineNumber = new char [( endLineNoPos - startLineNoPos) + 2 ];
806+ strncpy_s (lineNumber, ( endLineNoPos - startLineNoPos) + 2 , lineDetails->line + startLineNoPos, endLineNoPos - startLineNoPos);
807+ lineDetails->errorLineNo = strtoul (lineNumber, NULL , 0 ) - 1 ;
761808 delete[] lineNumber;
762809 lineDetails->filenameEnd = startLineNoPos - 1 ;
763810 retVal = true ;
@@ -809,9 +856,9 @@ bool ConsoleDialog::parseGCCErrorLine(LineDetails *lineDetails)
809856 bool retVal = false ;
810857 styleState = SS_FILENAME;
811858
812- int pos = 0 ;
859+ idx_t pos = 0 ;
813860 lineDetails->filenameStart = 0 ;
814- lineDetails->errorLineNo = - 1 ;
861+ lineDetails->errorLineNo = IDX_MAX ;
815862
816863 while (styleState != SS_EXIT)
817864 {
@@ -861,19 +908,19 @@ bool ConsoleDialog::parseGCCErrorLine(LineDetails *lineDetails)
861908
862909 case SS_LINENUMBER:
863910 {
864- int startLineNoPos = pos;
911+ idx_t startLineNoPos = pos;
865912 while (lineDetails->line [pos] >= ' 0' && lineDetails->line [pos] <= ' 9' && pos < lineDetails->lineLength )
866913 {
867914 ++pos;
868915 }
869916 if (pos < (lineDetails->lineLength + 1 )
870917 && lineDetails->line [pos] == ' :' )
871918 {
872- lineDetails->errorLineNo = atoi (lineDetails->line + startLineNoPos) - 1 ;
919+ lineDetails->errorLineNo = strtoul (lineDetails->line + startLineNoPos, NULL , 0 ) - 1 ;
873920
874921 // If the line number came out as 0, ie. there wasn't any,
875922 // then the line is not a gcc error
876- if (lineDetails->errorLineNo == - 1 )
923+ if (lineDetails->errorLineNo == IDX_MAX )
877924 {
878925 styleState = SS_EXIT;
879926 }
@@ -929,10 +976,12 @@ bool ConsoleDialog::parsePythonErrorLine(LineDetails *lineDetails)
929976
930977 bool retVal = false ;
931978 styleState = SS_BEGIN;
932- lineDetails->errorLineNo = - 1 ;
933- int pos = 0 ;
979+ lineDetails->errorLineNo = IDX_MAX ;
980+ idx_t pos = 0 ;
934981 while (styleState != SS_EXIT)
935982 {
983+ // lint -e{788} enum constant 'StyleState::SS_EXIT' not used within defaulted switch
984+ // That's normal since SS_EXIT is strictly used to exit the loop.
936985 switch (styleState)
937986 {
938987 case SS_BEGIN:
@@ -979,7 +1028,7 @@ bool ConsoleDialog::parsePythonErrorLine(LineDetails *lineDetails)
9791028 break ;
9801029
9811030 case SS_LINENUMBER:
982- lineDetails->errorLineNo = atoi (lineDetails->line + pos) - 1 ;
1031+ lineDetails->errorLineNo = strtoul (lineDetails->line + pos, NULL , 0 ) - 1 ;
9831032 styleState = SS_EXIT;
9841033 break ;
9851034
@@ -992,20 +1041,16 @@ bool ConsoleDialog::parsePythonErrorLine(LineDetails *lineDetails)
9921041 return retVal;
9931042}
9941043
995-
996-
997-
998-
999-
1000-
10011044void ConsoleDialog::onHotspotClick (SCNotification* notification)
10021045{
1003-
1046+ assert (m_console != NULL );
1047+ if (m_console)
1048+ {
10041049 int lineNumber = callScintilla (SCI_LINEFROMPOSITION, notification->position );
10051050 LineDetails lineDetails;
1006- lineDetails.lineLength = callScintilla (SCI_GETLINE, lineNumber);
1051+ lineDetails.lineLength = ( size_t ) callScintilla (SCI_GETLINE, lineNumber);
10071052
1008- if (lineDetails.lineLength > 0 )
1053+ if (lineDetails.lineLength != SIZE_MAX )
10091054 {
10101055 lineDetails.line = new char [lineDetails.lineLength + 1 ];
10111056 callScintilla (SCI_GETLINE, lineNumber, reinterpret_cast <LPARAM>(lineDetails.line ));
@@ -1016,5 +1061,5 @@ void ConsoleDialog::onHotspotClick(SCNotification* notification)
10161061 m_console->openFile (lineDetails.line + lineDetails.filenameStart , lineDetails.errorLineNo );
10171062 }
10181063 }
1019-
1064+ }
10201065}
0 commit comments