小编Vis*_*ale的帖子

C程序随机改变int的值

我真的很困惑.我有一个C服务器,它工作得很好,但后来我添加了一些代码,我认为它工作正常,直到我的程序随机开始将int的值更改为负值.

基本上我有我的服务器输出发送的总字节数和传输中途,总是大约2100000000字节,总字节变为负数.这是我输出文件的一个例子.如果你查看我的代码,这个值不能变成负数.所以我怀疑这是更奇怪的事情.

"345000","1470253912","59203","5592","2069901108"
"348000","1470253912","475539","4194","2092449162"
"351000","1470253912","830291","2796","2112043464"
"354000","1470253913","243217","1398","2133985176"
"357000","1470253913","708686","13980","-2135434834"
"360000","1470253914","173646","9786","-2109094024"
"363000","1470253914","514938","6990","-2089413400" 
Run Code Online (Sandbox Code Playgroud)

无论如何我添加的东西,我评论了它,我仍然遇到了同样的错误.仅供参考,我的代码在"NEW STUFF ADDED"标签下注释掉了.(我之所以添加它是因为这篇文章:在命令行上终止C程序,但确保编写完成后写入 )

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netdb.h>
    #include <arpa/inet.h>
    #include <sys/wait.h>
    #include <signal.h>
    #include <sys/time.h>



int PORT_NUM = 0; 
int RecordRate = 3000; 
FILE *fp;

typedef struct timeval timeval;
timeval time_;


void error(const char *msg)
{
    perror(msg);
    exit(1);
}

 //NEW STUFF ADDED
 //void sig_handler(int signo)
 //{
 //  if (signo == SIGINT) {
 // printf("received SIGINT\n"); …
Run Code Online (Sandbox Code Playgroud)

c flush integer-overflow server

-1
推荐指数
1
解决办法
160
查看次数

标签 统计

c ×1

flush ×1

integer-overflow ×1

server ×1