• 《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 }
  • 相关阅读:
    通过Logstash由SQLServer向Elasticsearch同步数据
    ELK +Nlog 分布式日志系统的搭建 For Windows
    Gulp 给所有静态文件引用加版本号
    Fluentdata详解
    jQuery Easy UI (适应屏幕分辨率大小)布局(Layout)
    什么是数据结构---算法
    WCF的学习之旅
    程序员必学之精华----软件工程
    译 .NET Core 3.0 发布
    Vue+Element UI 实现视频上传
  • 原文地址:https://www.cnblogs.com/zhuli19901106/p/3687673.html
Copyright © 2020-2023  润新知