微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Valgrind给getline给出错误

我有一个函数调用getline() ,它读取标准文本文件中的行。 这些行以rn结尾,因为这是规范所要求的,因为它是VCARD文件的“互联网标准”。

无论如何,我在OpenSUSE 11.3上通过Valgrind运行这个宝贝,并带有最新的GCC和Valgrind版本。 没有错误。 然而,由于与这个问题没有关系的原因,我把发行版切换到Back Track 4(基于Ubuntu),现在我得到了一吨Valgrind错误

==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x40164A1: (within /lib/ld-2.11.1.so) ==21536== by 0x4007C04: (within /lib/ld-2.11.1.so) ==21536== by 0x4002A2C: (within /lib/ld-2.11.1.so) ==21536== by 0x4014206: (within /lib/ld-2.11.1.so) ==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) ==21536== by 0x4000856: (within /lib/ld-2.11.1.so) ==21536== ==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x40164AC: (within /lib/ld-2.11.1.so) ==21536== by 0x4007C04: (within /lib/ld-2.11.1.so) ==21536== by 0x4002A2C: (within /lib/ld-2.11.1.so) ==21536== by 0x4014206: (within /lib/ld-2.11.1.so) ==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) ==21536== by 0x4000856: (within /lib/ld-2.11.1.so) --21536-- Warning: DWARF2 CFI reader: unhandled DW_OP_ opcode 0x55 --21536-- Warning: DWARF2 CFI reader: unhandled DW_OP_ opcode 0x55 --21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 --21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 --21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 --21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 --21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 --21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 --21536-- DWARF2 CFI reader: unhandled CFI instruction 0:10 ==21536== ==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x400B217: (within /lib/ld-2.11.1.so) ==21536== by 0x40031D0: (within /lib/ld-2.11.1.so) ==21536== by 0x4014206: (within /lib/ld-2.11.1.so) ==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) ==21536== by 0x4000856: (within /lib/ld-2.11.1.so) ==21536== ==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x400AF0F: (within /lib/ld-2.11.1.so) ==21536== by 0x40031D0: (within /lib/ld-2.11.1.so) ==21536== by 0x4014206: (within /lib/ld-2.11.1.so) ==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) ==21536== by 0x4000856: (within /lib/ld-2.11.1.so) ==21536== ==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x400B27A: (within /lib/ld-2.11.1.so) ==21536== by 0x40031D0: (within /lib/ld-2.11.1.so) ==21536== by 0x4014206: (within /lib/ld-2.11.1.so) ==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) ==21536== by 0x4000856: (within /lib/ld-2.11.1.so) ==21536== ==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x400A5DE: (within /lib/ld-2.11.1.so) ==21536== by 0x40030FE: (within /lib/ld-2.11.1.so) ==21536== by 0x4014206: (within /lib/ld-2.11.1.so) ==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) ==21536== by 0x4000856: (within /lib/ld-2.11.1.so) ==21536== ==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x400A5E6: (within /lib/ld-2.11.1.so) ==21536== by 0x40030FE: (within /lib/ld-2.11.1.so) ==21536== by 0x4014206: (within /lib/ld-2.11.1.so) ==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) ==21536== by 0x4000856: (within /lib/ld-2.11.1.so) ==21536== ==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x400AF0F: (within /lib/ld-2.11.1.so) ==21536== by 0x40030FE: (within /lib/ld-2.11.1.so) ==21536== by 0x4014206: (within /lib/ld-2.11.1.so) ==21536== by 0x4000C6C: (within /lib/ld-2.11.1.so) ==21536== by 0x4000856: (within /lib/ld-2.11.1.so) ==21536== ==21536== Invalid read of size 8 ==21536== at 0x40B4785: (within /lib/tls/i686/cmov/libc-2.11.1.so) ==21536== by 0x8049EFB: main (vcutil.c:496) ==21536== Address 0x419d1b0 is 8 bytes before a block of size 120 alloc'd ==21536== at 0x4025D2E: malloc (vg_replace_malloc.c:207) ==21536== by 0x409DF9D: getdelim (in /lib/tls/i686/cmov/libc-2.11.1.so) ==21536== by 0x408F3A2: getline (in /lib/tls/i686/cmov/libc-2.11.1.so) ==21536== by 0x804947C: getUnfolded (vcutil.c:299) ==21536== by 0x8049EFB: main (vcutil.c:496) ==21536== ==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x40B47AD: (within /lib/tls/i686/cmov/libc-2.11.1.so) ==21536== by 0x8049EFB: main (vcutil.c:496) ==21536== ==21536== Conditional jump or move depends on uninitialised value(s) ==21536== at 0x8049524: getUnfolded (vcutil.c:307) ==21536== by 0x8049EFB: main (vcutil.c:496)

我特别不知道这些线是指什么

--21536-- Warning: DWARF2 CFI reader: unhandled DW_OP_ opcode 0x55

意思。 自从我改变发行版之后,这些是新的。

用于C ++的VisualWorks Smalltalk IDE(Linux)

输出文件上做“rm”之后,C程序在哪里写输出

Linux何时/如何将共享库加载到地址空间?

文件描述符在哪里存储在进程内存中?

如何获得文件的扩展属性(UNIX / C)?

无论如何,作为参考,这里是我的问题:

VcStatus getUnfolded (FILE *const vcf,char **const buff) { //int const buffSize = 30; size_t linesize = 0; int done = 0; //Set to one if the next line checked does not entail unfolding static char* queue = NULL; //A queue to store the next line read in static int lineNum = 0; char* buffer = NULL; //The dynamic memory that will be linked to buf int valid_line = 0; //Set to one if the line contains characters other then whitespace char* temp; //Used to point to the location of rn in the buffer VcStatus error; //Initialize VcStatus with appropriate values error.code = OK; error.linefrom = lineNum; error.lineto = 0; //Special case for resetting getUnfolded() if (vcf == NULL){ lineNum = 0; if (queue != NULL) queue = NULL; error.linefrom = 0; error.lineto = 0; return error; } //copies any string contained in queue from last time into buffer if (queue != NULL) { buffer = malloc (strlen (queue)+1); strcpy (buffer,queue); strcpy (queue,""); } //If the end of file has been reached,last line is returned. if (feof (vcf) != 0) { queue = NULL; lineNum += 1; if (buffer != NULL) { if (strcmp (buffer,"") != 0)*buff = buffer; } else *buff = NULL; return error; } while (done == 0) { //Gets a new line from the vcf file,and returns null if there is no more data to be returned getline (&queue,&linesize,vcf); if (ferror(vcf) != 0) { error.code = IOERR; return error; } //Sets valid_line to 1 if the line read in contains any characters other then whitespace for (int i = 0; i < strlen (queue); i++){ if (queue[i] != 'r' && queue[i] != 'n' && queue[i] != ' ' && queue[i] != 't') valid_line = 1; } if (feof (vcf) && valid_line == 0) { queue = NULL; break; } if (valid_line == 1){ //Finds the 'internet standard' newline and replaces it with a null terminator temp = strstr (queue,"rn"); if (temp != NULL) strcpy (temp,""); //Sets the buffer equal to contents of queue and resets queue if buffer is empty if (buffer == NULL) { buffer = malloc (strlen (queue)+1); lineNum = lineNum + 1; strcpy (buffer,""); //Checks for leading whitespace to indicate a folded line,and unfolds }else if (queue [0] == ' ' || queue [0] == 't') { lineNum = lineNum + 1; buffer = realloc (buffer,strlen (buffer)+strlen (queue)+2); strcat (buffer,queue+1); strcpy (queue,""); //If both conditions above are false,buffer contains the next valid line }else{ error.lineto = lineNum; lineNum += 1; done = 1; } } } *buff = buffer; return error; }

…以及将testing数据发送给它的虚拟函数

int main () { FILE* fp = fopen ("test.vcf","r"); char * buff; getUnfolded (fp,&buff); }

test.vcf文件真的只是一个简单的文本文件

任何帮助将是惊人的。

如何决定在哪里存储每个用户的状态? 注册? 应用程序数据? 孤立的存储?

确保语句只有在按住某个键时才执行。

Linux堆分配

RegQueryValueEx REG_SZ

由于PROTOBUF服务器中的string数据typesvariables而导致段错误,并通过recv端的套接字来实现通信

您正在使用的valgrind版本已过时,因此不会抑制正确的输出。 这些错误仍然存​​在,只是因为它们在系统代码中而被压制。

您需要手动安装最新版本的valgrind

这是我使用的论坛帖子

http://ubuntuforums.org/showthread.PHP?t=1608001

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐