亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 2183 | 回復(fù): 3
打印 上一主題 下一主題

[C] if 整形判斷,報(bào)錯(cuò) “ Memory map: ” 應(yīng)該怎么解決。 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-12-05 16:26 |只看該作者 |倒序?yàn)g覽
本帖最后由 p0w3r 于 2015-12-05 16:32 編輯

代碼如下 ,   

導(dǎo)致出錯(cuò)的條件:

1、 “fail_count” 不存在 ---> 創(chuàng)建文件 ----> 出錯(cuò) .

2、 “fail_count” 存在 ---> 文件內(nèi)值為0 ----> 出錯(cuò) .

3、 "fail_count" 存在 ---> 文件內(nèi)值不為0 ----> 正常運(yùn)行 ---> 文件內(nèi)值重置為 0 ----> 退出 .

4、 在第三的基礎(chǔ)下再次執(zhí)行程序 , 文件內(nèi)值為0 ----> 出錯(cuò)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>


  4. #define RESET_MODULE        2
  5. #define RESET_SYSTEM        4
  6. #define FAIL_PATH        "/tmp/fail_count"

  7. static int existFile(const char * PATH);
  8. void reset_init(void);
  9. void unsuccess_add(void);

  10. int main(void) {
  11.         reset_init();
  12.         // for (int i = 0; i < RESET_SYSTEM; ++i)
  13.         // {
  14.         //         unsuccess_add();
  15.         // }
  16. }

  17. void unsuccess_add() {
  18.         FILE *file;
  19.         int i;
  20.         file = fopen(FAIL_PATH, "r");
  21.         fscanf(file, "%d", &i);
  22.         fclose(file);
  23.         file = fopen(FAIL_PATH, "w");
  24.         i++;
  25.         fprintf(file, "%d\n", i);
  26.         fclose(file);
  27. }

  28. void reset_init(void) {
  29.         FILE *file;
  30.         int val = 0;
  31.         if (existFile(FAIL_PATH)) {
  32.                 file = fopen(FAIL_PATH, "r");
  33.         } else {
  34.                 file = fopen(FAIL_PATH, "w+");
  35.         }
  36.         fscanf(file, "%d", &val);
  37.         fclose(file);
  38.         printf("%d\n", val);
  39. /*************** 出錯(cuò)開(kāi)始 *************/
  40.         if ( val != 0 ) {
  41.                 file = fopen(FAIL_PATH, "w");
  42.                 fprintf(file, "%d", 0);
  43.         }
  44. /************ 出錯(cuò)結(jié)束 ***************/
  45.         fclose(file);
  46. }

  47. static int existFile(const char * PATH) {
  48.     // include <unistd.h>
  49.     // F_OK:test for existence of file
  50.     int access_result = access(PATH, F_OK);
  51.     if (access_result == -1) {
  52.         return 0;
  53.     } else {
  54.         return 1;
  55.     }
  56. }
復(fù)制代碼
在  if ( val != 0 ) 的地方出現(xiàn)錯(cuò)誤如下
  1. root@debian7:/tmp# ./a.out
  2. 0
  3. *** glibc detected *** ./a.out: double free or corruption (top): 0x0000000001640010 ***
  4. ======= Backtrace: =========
  5. /lib/x86_64-linux-gnu/libc.so.6(+0x75be6)[0x7fcaff61cbe6]
  6. /lib/x86_64-linux-gnu/libc.so.6(cfree+0x6c)[0x7fcaff62198c]
  7. /lib/x86_64-linux-gnu/libc.so.6(fclose+0x14d)[0x7fcaff60db3d]
  8. ./a.out[0x4007f0]
  9. ./a.out[0x4006a5]
  10. /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd)[0x7fcaff5c5ead]
  11. ./a.out[0x4005b9]
  12. ======= Memory map: ========
  13. 00400000-00401000 r-xp 00000000 08:01 1478893                            /tmp/a.out
  14. 00600000-00601000 rw-p 00000000 08:01 1478893                            /tmp/a.out
  15. 01640000-01661000 rw-p 00000000 00:00 0                                  [heap]
  16. 7fcaf8000000-7fcaf8021000 rw-p 00000000 00:00 0
  17. 7fcaf8021000-7fcafc000000 ---p 00000000 00:00 0
  18. 7fcaff391000-7fcaff3a6000 r-xp 00000000 08:01 786436                     /lib/x86_64-linux-gnu/libgcc_s.so.1
  19. 7fcaff3a6000-7fcaff5a6000 ---p 00015000 08:01 786436                     /lib/x86_64-linux-gnu/libgcc_s.so.1
  20. 7fcaff5a6000-7fcaff5a7000 rw-p 00015000 08:01 786436                     /lib/x86_64-linux-gnu/libgcc_s.so.1
  21. 7fcaff5a7000-7fcaff728000 r-xp 00000000 08:01 786443                     /lib/x86_64-linux-gnu/libc-2.13.so
  22. 7fcaff728000-7fcaff928000 ---p 00181000 08:01 786443                     /lib/x86_64-linux-gnu/libc-2.13.so
  23. 7fcaff928000-7fcaff92c000 r--p 00181000 08:01 786443                     /lib/x86_64-linux-gnu/libc-2.13.so
  24. 7fcaff92c000-7fcaff92d000 rw-p 00185000 08:01 786443                     /lib/x86_64-linux-gnu/libc-2.13.so
  25. 7fcaff92d000-7fcaff932000 rw-p 00000000 00:00 0
  26. 7fcaff932000-7fcaff952000 r-xp 00000000 08:01 786455                     /lib/x86_64-linux-gnu/ld-2.13.so
  27. 7fcaffb40000-7fcaffb43000 rw-p 00000000 00:00 0
  28. 7fcaffb4e000-7fcaffb51000 rw-p 00000000 00:00 0
  29. 7fcaffb51000-7fcaffb52000 r--p 0001f000 08:01 786455                     /lib/x86_64-linux-gnu/ld-2.13.so
  30. 7fcaffb52000-7fcaffb53000 rw-p 00020000 08:01 786455                     /lib/x86_64-linux-gnu/ld-2.13.so
  31. 7fcaffb53000-7fcaffb54000 rw-p 00000000 00:00 0
  32. 7ffc99636000-7ffc99657000 rw-p 00000000 00:00 0                          [stack]
  33. 7ffc997ae000-7ffc997af000 r-xp 00000000 00:00 0                          [vdso]
  34. ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
  35. Aborted
  36. root@debian7:/tmp#
復(fù)制代碼

論壇徽章:
4
2015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:11IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-08-11 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-08-15 06:20:00
2 [報(bào)告]
發(fā)表于 2015-12-07 09:04 |只看該作者

/*************** 出錯(cuò)開(kāi)始 *************/
        if ( val != 0 ) {
                file = fopen(FAIL_PATH, "w");
                fprintf(file, "%d", 0);
        }
/************ 出錯(cuò)結(jié)束 ***************/
        fclose(file);

fclose(file);

最后一個(gè)語(yǔ)句fclose(file);放錯(cuò)位置了

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2015-12-07 09:38 |只看該作者
回復(fù) 2# happy_fish100


    唉  ,真為自己的智商捉急啊 。。。
    原來(lái)這個(gè)錯(cuò)誤就是 , 找不到要關(guān)閉的文件流。

論壇徽章:
224
2022北京冬奧會(huì)紀(jì)念版徽章
日期:2015-08-10 16:30:32操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-02-18 06:20:00操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-03-01 06:20:00操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-03-02 06:20:0015-16賽季CBA聯(lián)賽之上海
日期:2019-09-20 12:29:3219周年集字徽章-周
日期:2019-10-01 20:47:4815-16賽季CBA聯(lián)賽之八一
日期:2020-10-23 18:30:5320周年集字徽章-20	
日期:2020-10-28 14:14:2615-16賽季CBA聯(lián)賽之廣夏
日期:2023-02-25 16:26:26CU十四周年紀(jì)念徽章
日期:2023-04-13 12:23:1015-16賽季CBA聯(lián)賽之四川
日期:2023-07-25 16:53:45操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-05-10 19:22:58
4 [報(bào)告]
發(fā)表于 2015-12-07 23:10 |只看該作者
好牛哦,直接看匯編代碼了
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專(zhuān)區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP