复审代码为C语言代码,过程式的实现了需求。编程
代码文件为共计620行的单文件,代码中使用多个函数封装了执行过程当中的多种操做。数组
代码中也存在问题:安全
1.做为一个工程化项目,单文件的方式有欠考虑。ide
2.代码中的部分变量名,如son和mo,不便于理解。函数
3.没有模测试,仅能经过结果测试程序是否正确。oop
4.没有注释。测试
复审结果以下:(其中N/A表明无效项)ui
General | ||
Does the code work? Does it perform its intended function, the logic is correct etc. | Y | |
Is all the code easily understood? | Y | |
Does it conform to your agreed coding conventions? | N/A | |
Is there any redundant or duplicate code? | N | |
Is the code as modular as possible? | Y | |
Can any global variables be replaced? | Y | |
Is there any commented out code? | N | |
Do loops have a set length and correct termination conditions? | N | |
Can any of the code be replaced with library functions? | N | |
Can any logging or debugging code be removed? | N | |
Security | ||
Are all data inputs checked (for the correct type, length, format, and range) and encoded? | N | |
Where third-party utilities are used, are returning errors being caught? | N/A | |
Are output values checked and encoded? | Y | |
Are invalid parameter values handled? | N | |
Documentation | ||
Do comments exist and describe the intent of the code? | N | |
Are all functions commented? | N | |
Is any unusual behavior or edge-case handling described? | N | |
Is the use and function of third-party libraries documented? | N/A | |
Are data structures and units of measurement explained? | N/A | |
Is there any incomplete code? If so, should it be removed or flagged with a suitable marker like ‘TODO’? | N | |
Testing | ||
Is the code testable? i.e. don’t add too many or hide dependencies, unable to initialize objects, test frameworks can use methods etc. | Y | |
Do tests exist and are they comprehensive? i.e. has at least your agreed on code coverage. | N | |
Do unit tests actually test that the code is performing the intended functionality? | N | |
Are arrays checked for ‘out-of-bound’ errors? | N | |
Could any test code be replaced with the use of an existing API? | N |
细化分析:spa
概要:debug
代码能够正常工做,在正确的输入下能够获得预期的结果。可是因为没有进行错误处理,致使输入错误值(如n<0)程序崩溃。
代码可读性较好,函数名、变量名基本能体现所表明含义。可是变量名使用依然不是很是清晰,如全局变量能够考虑使用使用g_做为开头。又如,代码中的分子和分母取名为son和mo,能够考虑使用numerator和denominator。缩进、括号位置、Tab/空格均保持一致。
代码精炼,没有多余的内容。主要功能均使用函数进行封装,莫花花结构较好。
代码中使用大量的全局变量,大数组做为全局变量会占用不少不须要的空间,这种实现方式效果很差。建议使用局部数组+指针进行传参。
安全:
全部输入未进行检查,输入非法参数或非法文件会致使程序崩溃。
程序仅在正确输入状况下获得正确的结果。
文档:
单文件c代码紧凑,未出现任何文档类注释。
测试:
程序中不存在测试用代码。测试时手动构造测试。
经测试,合法状况的传参能够获得正确的结果,非法传参结果不正确或崩溃。
因为做者使用过程式编程,很容易就能够遍历全部分支。