-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


Representative Line: Nasal String Length

Среда, 03 Декабря 2014 г. 14:00 + в цитатник

Dariusz isnt sure what this line of code was meant to do. At his best guess, it was supposed to find an improperly terminated C string and add a null terminator character after it:

buf[strlen(buf)] = '\0';

Of course, if the string werent null terminated, weve entered nasal demon territory- the behavior of strlen is undefined for non-null terminated strings. If you present a C-compiler an undefined construct, it is allowed to do anything it likes, including make demons fly out of your nose.

A howitzer cannon for shooting yourself in the foot

But even on null terminated strings, this code is dangerous. Since arrays in C, like any sane language, are zero indexed, this code may attempt to access memory beyond the end of the array, overwriting whatevers there with a null terminator.

This is the sort of code that happens when Java programmers attempt to write C, without understanding how theyll shoot themselves in the foot

http://thedailywtf.com/articles/nasal-string-length

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку