开发者

Corrupted ints and sscanf -- and other C related memory issues

I've got a function control() which is threaded. It calls another function which parses some server responses. Here is some verbose initialization which doesn't take care of my problem.

    int oct1 = 0;
    int oct2 = 0;
    int oct3 = 0;
    int oct4 = 0;
    int p1 = 0;
    int p2 = 0;

    sscanf(passive_ip, "%i,%i,%i,%i,%i,%i", &oct1, &oct2, &oct3, &oct4, &p1, &p2);

I often find my results messed up. For example:

S->C: 227 Entering Passive Mode (128,111,40,221,206,170)
The Parsed Result: 128.111.40.221 206,170

S->C: 227 Entering Passive Mode (128,111,40,221,80,8)
The Parsed Result: 128.111.40.221 80,8170

S->C: 227 Entering Passive Mode (128,111,40,221,241,196)
The Parsed Result: 128.111.40.221 241,196

S->C: 227 Entering Passive Mode (128,开发者_如何学JAVA111,40,221,70,216)
The Parsed Result: 128.111.40.221 70,2166

Notice how old values are appended / jumbled with new values. Any clue as to why this might happen?


It looks like you are somehow forgetting to terminate passive_ip. Whatever you're doing should be sure to end it with a terminating null byte.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜