zoukankan      html  css  js  c++  java
  • 《Cracking the Coding Interview》——第12章:测试——题目2

    2014-04-24 23:15

    题目:你有一段程序,运行了十次每次都在不同的地方崩掉了。已知这段程序只用了标准C或C++库函数,请问有什么思路来找出问题所在。

    解法:1. 时间戳每次都不同。2. 随机变量每次都不同。3. 局部变量的初值,每次可能不同,不过就算没初始化,很多时候那个无效值其实也是固定的,和编译器操作系统之类的相关。4. 外部依赖引起的问题,这点不太容易说清楚,简而言之:那是隔壁组的问题。5. 内存泄露,读到了非法区域,数据的确是不确定的。

    代码:

     1 // 12.2 A program crashes when it is run. After running it on a same machine for 10 times, it crashes every time on a different spot.
     2 // It is single-threaded, and uses only C-standard libraries.
     3 // Answer:
     4 //    One different thing when the program is run every time, is the timestamp.
     5 //    So you might check the code where functions about time is called, or timestamp is used.
     6 //    To debug a bugged system, use logging strategy to aid you.
     7 //    Two tips for debugging:
     8 //        1. start printing log at both ends, every time you crashes, shrink the range of debugging by half. Use the ideas of binary search for debug.
     9 //        2. print every suspicious variable if necessary.
    10 int main()
    11 {
    12     return 0;
    13 }
  • 相关阅读:
    node.js中用户密码的加密
    linux下高可用LVS搭建及配置方法
    在Centos 5.x或6.x上安装RHEL EPEL Repo
    shell脚本 expect 实现自动登陆
    platform 收集linux/windows操作系统信息
    市面上比较流行的图表展示
    django作业2
    django实现分片上传文件
    linux下大于2T硬盘格式化方法
    django之第二天
  • 原文地址:https://www.cnblogs.com/zhuli19901106/p/3687673.html
Copyright © 2011-2022 走看看