STL MAP 에 관하여 여쭈어보고 싶은게 있습니다.

jang5497의 이미지

Map을 이용하여 자료를 입력받아 저장하는 프로젝트 A가 있습니다.
프로젝트 A는 단독으로 실행하였을때 오류없이 잘 돌아갑니다.
기존에 저희 회사에서 쓰고있는 MFC 다이얼로그 내부에 프로젝트 A를 넣어서 사용하려고 넣었는데
Map insert 부분에서 오류가 난것을 확인했습니다. 똑같은 코드를 다이얼로그에 넣어서 사용할뿐인데......
xtree.cpp Line339
map/set iterator not decrementable
에러가 떠서 찾아간결과

_Pairib insert(const value_type& _Val)
{ // try to insert node with value _Val
_Nodeptr _Trynode = _Root();
_Nodeptr _Wherenode = _Myhead;
bool _Addleft = true; // add to left of head if tree empty
while (!_Isnil(_Trynode))
{ // look for leaf to insert before (_Addleft) or after
_Wherenode = _Trynode;
_Addleft = _DEBUG_LT_PRED(this->comp,
this->_Kfn(_Val), _Key(_Trynode));
_Trynode = _Addleft ? _Left(_Trynode) : _Right(_Trynode);
}

if (this->_Multi)
return (_Pairib(_Insert(_Addleft, _Wherenode, _Val), true));
else
{ // insert only if unique
iterator _Where = _TREE_ITERATOR(_Wherenode);
if (!_Addleft)
; // need to test if insert after is okay
else if (_Where == begin())
return (_Pairib(_Insert(true, _Wherenode, _Val), true)) // <-- 여기!!
else
--_Where; // need to test if insert before is okay

if (_DEBUG_LT_PRED(this->comp,
_Key(_Where._Mynode()), this->_Kfn(_Val)))
return (_Pairib(_Insert(_Addleft, _Wherenode, _Val), true)); // <-- 여기
else
return (_Pairib(_Where, false));
}

이 코드에서 에러가 나더군요. 보시면 알겠지만 stl map의 insert 부분에서 난 오류입니다 좀더 세세히 말씀 드리자면
while (!_Isnil(_Trynode))
{ // look for leaf to insert before (_Addleft) or after
_Wherenode = _Trynode;
_Addleft = _DEBUG_LT_PRED(this->comp,
this->_Kfn(_Val), _Key(_Trynode));
_Trynode = _Addleft ? _Left(_Trynode) : _Right(_Trynode);
}
코드의 while 조건문의 함수

static _Charref _Isnil(_Nodeptr _Pnode)
{ // return reference to nil flag in node
return ((_Charref)(*_Pnode)._Isnil);
}

위코드에서 ((_Charref)(*_Pnode)._Isnil 값이
단독 프로젝트에서는 0을 리턴하는데
MFC 다이얼로그에 올리니 100을 리턴하더군요....

둘 다 조건이 동일하지만 환경에서 저런 오류가 나는데....
map 자료형의 오류라고 생각하지않지만 어떻게 저부분에서 다른 값이 나올까요....
차이점이라면 다이얼로그내 에서 여러 쓰레드가 돌고 있긴 하지만 자원에 대한 공유도 없으며
경쟁또한 하지않습니다...
lock을 걸어서 해보았지만 소용이 없었습니다....

klyx의 이미지

똑같은 코든데 어딘되고 어딘 안된다는 건 그냥 안된다는 거고, 십중팔구 '정의되지 않은 동작'에 의존하고 있는 겁니다.
포인터관련한 에러는 죽는 곳과 원인인 곳이 전혀 다를수 있기 때문에 STL코드를 백날 디버깅해봐야 답은 안나옵니다.
원본 소스코드를 올리셔야 도움받을 수 있을겁니다.

twinwings의 이미지

C++ 표준 라이브러리, (iostream 계열 이었던 듯..stringstream?)

사용하면서 도대체 이해할 수 없는 동작을 한 적이 있었는데

원인이, 포인터 조작하다가 잘못 건드려서 STL 객체 내부를 실수로 건드렸더군요.

이런 경우나, 혹은 MAP에 들어가는 자료형의 생성자에서 예외등의 문제가 발생하는건 아닐까요?

익명 사용자의 이미지

map의 메모리 영역을 memset으로 초기화 하고 있지는 않은지 살펴보세요
컴파일러를 바꿨는데 stl에서 자꾸 런타임 에러가 나서 봤더니
구조체나 클래스를 초기화하는데 memset을 사용하는데 vector를 멤버로 가지고 있어서 죽는경우도 봤습니다

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.