关于如何扩展复杂且难懂的C代码的一点经验谈
有时,我们会希望扩展一些现有的C代码。这些代码可能经历了相当久的运行考验——它们至少目前工作起来没有问题——然而,它们可能存在各种各样的问题,比如:
- 缺少注释。
- 过分使用的goto语句。
- 变量名不规范。
- 逻辑复杂难懂。
- 过分使用表达式赋值(if (foo = bar()) {})
- 直接返回函数返回值(这是合法的,但会给增加功能带来困难)
要扩展这类代码是一件有挑战的事情。
共 367 篇文章。
有时,我们会希望扩展一些现有的C代码。这些代码可能经历了相当久的运行考验——它们至少目前工作起来没有问题——然而,它们可能存在各种各样的问题,比如:
要扩展这类代码是一件有挑战的事情。
似乎在处理>和<时,和 DCE 不太一样,改天写个test case看看。
生成UUID from 2006 Penguin, smashing time! on February 4, 2006 11:36 PM
1 2 3 4 5 6 7 8 9 10#include <stdio.h> #include <uuid.h> main() { uuid_t *uuid; char *s; uuid = (uuid_t*)malloc(sizeof(uuid_t)); uuidgen(uuid,1); uuid_to_string(uuid,&s,NULL); printf("%s\\n",s); }
一个很简单的生成UUID的例子。… Read More
Today we have frozen the RELENG_5 and RELENG_6 branches, for the upcoming 5.5-RELEASE and 6.1-RELEASE. Unfortunately, the www.freebsd.org is not accessable from the mainland China right now.
我们将在大约月底的时候开始代码冻结,并准备两个新的RELEASE。我们的主要精力将集中于FreeBSD 6.1,而FreeBSD 5.5则集中于修正严重问题。近期发现的一系列功能和性能上的改进,将合并到这两个分支上。
今天一条内部消息(很快会正式公布)说我们得到了一个强悍的代码静态分析工具的授权。希望这能够为我们的开发带来新的想法,登录上去看了看,感觉很有挑战,许多似是而非的问题,到底是不是真的问题,其实都需要我们去手工地阅读代码和重新验证。
学习一种语言最快的方法就是逼自己干什么事情的时候都用它——有一个利用了Python来实现的shell——iPython,可以用来代替默认的shell。
Python includes a Regular Expression implementation, called re. However, I thought that I have hit a bug.
The following regular expression is apparantly wrong, but Python spend much CPU time to give a mismatch:
_mailcheck = re.compile("^(\w|.){3,25}$")
_mailcheck.match(“foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo”)
I think the “.” would override anything (including “\w”), but this does not happen…
提了个patch不到10分钟就上去了,赞一个……
最近几天开始琢磨Twisted了。打算用Twisted来做一些东西,不过不知道它的线程是否能使用阻塞I/O……
今天被一个程序折腾了很久。大致的流程是这样:
事件处理:
锁的机制没有大毛病,可是数据死活不对。