私はメッセージError reading characters of string
Unable to read memory
を受け取り続けます。私はCString.Format()関数が呼び出されたときにすべてが順番になっているように見えるので、それを修正する方法がわかりません。ここでCString Format()がメモリを読み取れません。
は、エラーが発生しstrnlen.cppのスポットです:これはstrnlen呼び出している関数である
そして、ここでは、休憩の時に地元の人々です。 cpp(最後の行はブレークが発生する場所です):
char comp[50];
gethostname(comp,50);
CString textmsg;
textmsg.Format("%s %s: %s",TEXT,comp, m_edit_message);
m_edit_messageはCString変数です。最後に、ここで
は、エラーの発生時にコールスタックです:
NetChess.exe!common_strnlen_c<unsigned char>(const unsigned char * const string, const unsigned int maximum_count) Line 36 C++
NetChess.exe!common_strnlen_simd<0,unsigned char>(const unsigned char * const string, const unsigned int maximum_count) Line 94 C++
NetChess.exe!common_strnlen<unsigned char>(const unsigned char * const string, const unsigned int maximum_count) Line 153 C++
NetChess.exe!strnlen(const char * string, unsigned int maximum_count) Line 165 C++
NetChess.exe!__crt_stdio_output::output_processor<char,__crt_stdio_output::string_output_adapter<char>,__crt_stdio_output::standard_base<char,__crt_stdio_output::string_output_adapter<char> > >::type_case_s_compute_narrow_string_length(const int maximum_length, char __formal) Line 2268 C++
NetChess.exe!__crt_stdio_output::output_processor<char,__crt_stdio_output::string_output_adapter<char>,__crt_stdio_output::standard_base<char,__crt_stdio_output::string_output_adapter<char> > >::type_case_s() Line 2255 C++
NetChess.exe!__crt_stdio_output::output_processor<char,__crt_stdio_output::string_output_adapter<char>,__crt_stdio_output::standard_base<char,__crt_stdio_output::string_output_adapter<char> > >::state_case_type() Line 1999 C++
NetChess.exe!__crt_stdio_output::output_processor<char,__crt_stdio_output::string_output_adapter<char>,__crt_stdio_output::standard_base<char,__crt_stdio_output::string_output_adapter<char> > >::process() Line 1644 C++
NetChess.exe!common_vsprintf<__crt_stdio_output::standard_base,char>(const unsigned __int64 options, char * const buffer, const unsigned int buffer_count, const char * const format, __crt_locale_pointers * const locale, char * const arglist) Line 163 C++
NetChess.exe!__stdio_common_vsprintf(unsigned __int64 options, char * buffer, unsigned int buffer_count, const char * format, __crt_locale_pointers * locale, char * arglist) Line 235 C++
NetChess.exe!_vscprintf_l(const char * const _Format, __crt_locale_pointers * const _Locale, char * _ArgList) Line 1655 C++
NetChess.exe!_vscprintf(const char * const _Format, char * _ArgList) Line 1672 C++
[External Code]
NetChess.exe!CMessageSend::OnOK() Line 60 C++
NetChess.exe!_AfxDispatchCmdMsg(CCmdTarget * pTarget, unsigned int nID, int nCode, void(CCmdTarget::*)() pfn, void * pExtra, unsigned int nSig, AFX_CMDHANDLERINFO * pHandlerInfo) Line 77 C++
NetChess.exe!CCmdTarget::OnCmdMsg(unsigned int nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO * pHandlerInfo) Line 372 C++
NetChess.exe!CDialog::OnCmdMsg(unsigned int nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO * pHandlerInfo) Line 85 C++
NetChess.exe!CWnd::OnCommand(unsigned int wParam, long lParam) Line 2779 C++
NetChess.exe!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2092 C++
NetChess.exe!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2078 C++
NetChess.exe!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 265 C++
NetChess.exe!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 418 C++
[External Code]
NetChess.exe!CWnd::IsDialogMessageA(tagMSG * lpMsg) Line 193 C++
NetChess.exe!CWnd::PreTranslateInput(tagMSG * lpMsg) Line 4586 C++
NetChess.exe!CDialog::PreTranslateMessage(tagMSG * pMsg) Line 80 C++
NetChess.exe!CWnd::WalkPreTranslateTree(HWND__ * hWndStop, tagMSG * pMsg) Line 3358 C++
NetChess.exe!AfxInternalPreTranslateMessage(tagMSG * pMsg) Line 233 C++
NetChess.exe!CWinThread::PreTranslateMessage(tagMSG * pMsg) Line 777 C++
NetChess.exe!AfxPreTranslateMessage(tagMSG * pMsg) Line 252 C++
NetChess.exe!AfxInternalPumpMessage() Line 178 C++
NetChess.exe!CWinThread::PumpMessage() Line 900 C++
NetChess.exe!CWinThread::Run() Line 629 C++
NetChess.exe!CWinApp::Run() Line 787 C++
NetChess.exe!AfxWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 47 C++
NetChess.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 26 C++
[External Code]
MessageSend.cpp
// MessageSend.cpp : implementation file
//
#include "stdafx.h"
#include "NetChess.h"
#include "MessageSend.h"
#include "NetChessDoc.h"
#include "NetChessView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////////////////// CMessageSend dialog
bool BoundsCheck2(char *myTestArray, unsigned int expectedSize);
CMessageSend::CMessageSend(CWnd* pParent)
: CDialog(CMessageSend::IDD, pParent)
{
//{{AFX_DATA_INIT(CMessageSend)
m_edit_message = _T("");
m_edit_receive_message = _T("");
//}}AFX_DATA_INIT
}
void CMessageSend::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMessageSend)
DDX_Text(pDX, IDC_EDIT_MESSAGE, m_edit_message);
DDV_MaxChars(pDX, m_edit_message, 50000);
DDX_Text(pDX, IDC_EDIT_RECEIVE_MESSAGE, m_edit_receive_message);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMessageSend, CDialog)
//{{AFX_MSG_MAP(CMessageSend)
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////////////////CMessageSend message handlers
void CMessageSend::OnOK()
{
//msgDlg.m_edit_send_message
UpdateData(TRUE);
char comp[50];
if (BoundsCheck2(comp, 50))
gethostname(comp,50);
CString textmsg;
textmsg.Format("%s %s: %s",TEXT,comp, (CString) m_edit_message);
m_edit_receive_message += (CString)comp + ": " + m_edit_message + (CString)"\r\n";;
((CNetChessView*)((CFrameWnd*)(AfxGetApp()->m_pMainWnd))->GetActiveView())->SendSockData((unsigned char*)textmsg.GetBuffer(0),textmsg.GetLength());
//textmsg.ReleaseBuffer(0);
m_edit_message = "";
UpdateData(FALSE);
CWnd* wnd= GetDlgItem(IDC_EDIT_RECEIVE_MESSAGE);
wnd->PostMessage(WM_VSCROLL,SB_BOTTOM,0);
//CDialog::OnOK();
}
void CMessageSend::SetReceiveData(char* data)
{
m_edit_receive_message += (data + (CString)"\r\n");
UpdateData(FALSE);
CWnd* wnd= GetDlgItem(IDC_EDIT_RECEIVE_MESSAGE);
wnd->PostMessage(WM_VSCROLL,SB_BOTTOM,0);
}
void CMessageSend::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
bool BoundsCheck2(char *myTestArray, unsigned int expectedSize)
{
//Reference: Reference: http://lelanthran.com/deranged/?p=182
bool status = true;
unsigned int count = 0;
//perform bounds checkes on data1; just to be safe
for (size_t i = 0; i < sizeof(myTestArray)/sizeof(myTestArray[0]); i++) {
count++;
}
if (count <= expectedSize)
status = true;
else
status = false;
return status;
}
MessageSend.h
#if !defined(AFX_MESSAGESEND_H__08C3FB4D_9E1E_4AF9_951F_7ED1033E3B16__INCLUDED_)
#define AFX_MESSAGESEND_H__08C3FB4D_9E1E_4AF9_951F_7ED1033E3B16__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MessageSend.h : header file
//
///////////////////////////////////////////CMessageSend dialog
class CMessageSend : public CDialog
{
// Construction
public:
CMessageSend(CWnd* pParent = NULL);
void SetReceiveData(char* data);
// standard constructor
// Dialog Data
//{{AFX_DATA(CMessageSend)
enum { IDD = IDD_DIALOG_MESSAGE };
CString m_edit_message;
CString m_edit_receive_message;
//}}AFX_DATA
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
virtual void OnOK();
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
DECLARE_MESSAGE_MAP()
};
#endif // !defined(AFX_MESSAGESEND_H__08C3FB4D_9E1E_4AF9_951F_7ED1033E3B16__INCLUDED_)
この上の任意の助けもあり感謝。 、 - (ポインタのサイズも32ビットに4になる)と、常に -
bool BoundsCheck2(char *myTestArray, unsigned int expectedSize)
// ...
for (size_t i = 0; i < sizeof(myTestArray)/sizeof(myTestArray[0]); i++) {
count++;
}
は、あなたが何を考えてやっていない
、sizeof(myTestArray)/sizeof(myTestArray[0]
は8に等しい:
「テキスト」とは何ですか?どのように初期化されますか? 'm_edit_message'とは何ですか?どのように初期化されますか? 'gethostname'への呼び出しは成功しましたか?私の推測*は、 'TEXT'か' m_edit_message'のどちらかが普通のC文字列ポインタ(または配列)ではなく、Cスタイルの文字列への明示的なキャストなしには本当に使用できない 'CString'オブジェクトのようなものですポインタ。 –
また、それは何ですか? [最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve)で再現可能なエラーを作成してください。 –
VSが作成/使用している変数です – Chris