Unhandled exception VS2010 C++

送分小仙女□ 提交于 2019-12-11 12:26:57

问题


I am trying to make a socket on windows to connect to a server.

I am using the code from msdn's website, the winsock client code.
(Link: msdn.microsoft.com/en-us/library/windows/desktop/ms737591(v=vs.100).aspx )

In any case, when I try debugging said code I get the error message:

Unhandled exception at 0x58a714cf (msvcr100d.dll) in Application.exe: 0xC0000005: Access violation reading location 0x00000032.

It asks me if I want to break or continue, if I continue the same error message simply keeps popping up. If I press break it takes me to line 1643 in the file output.c .

Simply put, I have no idea about what to do to make it work, and I'd appreciate any help given.

EDIT:

A reply to all comments given thus far:

The surrounding relevant code in output.c is:

if (flags & (FL_LONG|FL_WIDECHAR)) {
                if (text.wz == NULL) /* NULL passed, use special string */
                    text.wz = __wnullstring;
                bufferiswide = 1;
                pwch = text.wz;
                while ( i-- && *pwch )
                    ++pwch;
                textlen = (int)(pwch - text.wz);
                /* textlen now contains length in wide chars */
            } else {
                if (text.sz == NULL) /* NULL passed, use special string */
                    text.sz = __nullstring;
                p = text.sz;
                while (i-- && *p) //THIS IS WHERE IT BREAKS
                    ++p;
                textlen = (int)(p - text.sz);    /* length of the string */
            }

This is not code that I have written but innate code that already exists.

EDIT NR 2: This is a printscreen displaying my call stack. I do not have 10 reputation so I cannot show the image, so here is a link to the image:

http://tinypic.com/r/5n6ww9/5

On it you can see my call stack


回答1:


The file output.c has the code that handles the printf family of functions.

The fact that you have an error here is probably due to a malformed printf function call in your code. Maybe you have specified an invalid print format or have not provided enough arguments.

When your program crashes, click Break and look at the call stack in the debugging windows to see where - in your code - the function is called, and with what arguments.

I suspect you are trying to print a NULL string or something. When you have found the printf call (if that's what it is), edit your question to show that section of source code and/or use the debugger to examine the variables used a arguments to the function and make sure they are all correct.

Without seeing the code that you've written, at the location of the crash, it's not possible to give a more precise answer.




回答2:


Or you may insert a null string to CString.format like below:

CString str;
str.format("%s"); //A null string

where it should be

str.format("%s",mes);

where mes is char mes[20] for example

or any other variable

So the point is there may be some mistake in CString.format or Printf

Good Luck.



来源:https://stackoverflow.com/questions/20840064/unhandled-exception-vs2010-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!