Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix passing long environment variables to the debugger #87

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions src/MICmnStreamStdin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifdef _WIN32
#include "Platform.h"
#endif
#include <iostream>
#include <string.h>

// In-house headers:
Expand All @@ -28,7 +29,7 @@
// Throws: None.
//--
CMICmnStreamStdin::CMICmnStreamStdin()
: m_strPromptCurrent("(gdb)"), m_bShowPrompt(true), m_pCmdBuffer(nullptr) {}
: m_strPromptCurrent("(gdb)"), m_bShowPrompt(true) {}

//++
// Details: CMICmnStreamStdin destructor.
Expand Down Expand Up @@ -61,9 +62,7 @@ bool CMICmnStreamStdin::Initialize() {
MI::ModuleInit<CMICmnLog>(IDS_MI_INIT_ERR_LOG, bOk, errMsg);
MI::ModuleInit<CMICmnResources>(IDS_MI_INIT_ERR_RESOURCES, bOk, errMsg);

if (bOk) {
m_pCmdBuffer = new char[m_constBufferSize];
} else {
if (!bOk) {
CMIUtilString strInitError(CMIUtilString::Format(
MIRSRC(IDS_MI_INIT_ERR_STREAMSTDIN), errMsg.c_str()));
SetErrorDescription(strInitError);
Expand Down Expand Up @@ -94,11 +93,6 @@ bool CMICmnStreamStdin::Shutdown() {

ClrErrorDescription();

if (m_pCmdBuffer != nullptr) {
delete[] m_pCmdBuffer;
m_pCmdBuffer = nullptr;
}

bool bOk = MIstatus::success;
CMIUtilString errMsg;

Expand Down Expand Up @@ -186,33 +180,22 @@ bool CMICmnStreamStdin::GetEnablePrompt() const { return m_bShowPrompt; }
const char *CMICmnStreamStdin::ReadLine(CMIUtilString &vwErrMsg) {
vwErrMsg.clear();

// Read user input
const char *pText = ::fgets(&m_pCmdBuffer[0], m_constBufferSize, stdin);
if (pText == nullptr) {
std::getline(std::cin, m_pCmdString);

if (std::cin.eof()) {
#ifdef _MSC_VER
// Was Ctrl-C hit?
// On Windows, Ctrl-C gives an ERROR_OPERATION_ABORTED as error on the
// command-line.
// The end-of-file indicator is also set, so without this check we will exit
// next if statement.
// command-line and the end-of-file indicator is also set.
if (::GetLastError() == ERROR_OPERATION_ABORTED)
return nullptr;
#endif
if (::feof(stdin)) {
const bool bForceExit = true;
CMIDriver::Instance().SetExitApplicationFlag(bForceExit);
} else if (::ferror(stdin) != 0)
vwErrMsg = ::strerror(errno);
const bool bForceExit = true;
CMIDriver::Instance().SetExitApplicationFlag(bForceExit);
} else if (std::cin.fail()) {
vwErrMsg = ::strerror(errno);
return nullptr;
}

// Strip off new line characters
for (char *pI = m_pCmdBuffer; *pI != '\0'; pI++) {
if ((*pI == '\n') || (*pI == '\r')) {
*pI = '\0';
break;
}
}

return pText;
return m_pCmdString.c_str();
}
3 changes: 1 addition & 2 deletions src/MICmnStreamStdin.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ class CMICmnStreamStdin : public CMICmnBase,
CMIUtilString m_strPromptCurrent; // Command line prompt as shown to the user
bool m_bShowPrompt; // True = Yes prompt is shown/output to the user (stdout),
// false = no prompt
static const int m_constBufferSize = 2048;
char *m_pCmdBuffer;
std::string m_pCmdString;
};