void sdsIncrLen(sds s,int incr) { struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); if(incr >= 0) assert(sh->free >=(unsigned int)incr); else assert(sh->len >= (unsigned int)(-incr)); sh->len += incr; sh->free -= incr; s[sh->len] = '\0'; }
这个函数用来计算调整sds字符串中len和free的大小。每次对sds字符串通过操做以后,字符串的len和free的大小都会变更。express
函数:函数
void assert( int expression );
先计算表达式expression,若是expression为真,则assert()无任何做用;若是expression为假,则函数先向标准错误流stderr打印一条出错信息,而后经过abort来终止程序运行。
本质上,assert是一个宏,并非函数。code