[英]strtok - buffer overrun
c ++函數, strtok() cplusplus.com
如果未正確終止str,此示例是否會遭受緩沖區溢出的困擾?
/* strtok example */
/* source - cplusplus.com (see link below) */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-"); // walk the stack?
}
return 0;
}
如果str不能以“ \\ 0”正確終止,則不可能
pch = strtok (NULL, " ,.-");
走棧?
謝謝!
如果字符串不是以空字符結尾的,那么大多數字符串處理函數都會走到最后。
但是,在您的代碼示例中, str
被終止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.