Tuesday, January 26th, 2016 04:26 pm
So, you've got a code in C that needs to allocate X objects of size Y. So, you start with malloc(X*Y). Then you discover X*Y may produce overflow, so you make function alloc(X, Y) that checks for overflows.

And then of course everybody starts using it as alloc(1, X*Y). Because it's the same thing, right?
Page 1 of 3 << [1] [2] [3] >>
[identity profile] anatoly borodin (from livejournal.com)
Wednesday, January 27th, 2016 03:00 am (UTC)
*calloc
Wednesday, January 27th, 2016 04:22 am (UTC)
Это что-то из мира embedded? Потому что аллокация размеров даже близких к величинам где начинается overflow of X*Y выглядит странно, по меньшей мере.
Wednesday, January 27th, 2016 04:45 am (UTC)
Странные люди, я всегда calloc() использовал именно как положоно по уставу.
Wednesday, January 27th, 2016 07:34 am (UTC)
Какие злые люди. :)
Wednesday, January 27th, 2016 09:13 am (UTC)
Язык программирования С должен быть разрушен.
Wednesday, January 27th, 2016 09:21 am (UTC)
в твоем каменте чувствуется обида и зависть, молодой джавист
Wednesday, January 27th, 2016 10:30 am (UTC)
And what's not the same here? Either we have enough memory to allocate or we don't.

Pardon my ignorance (have very little C experience).
Wednesday, January 27th, 2016 10:39 am (UTC)
you could have enough memory but not enough integers to count it
Wednesday, January 27th, 2016 11:14 am (UTC)
Нет, это люди неспособные программировать, должны быть направлены на соответствующие их скромным способностям рабочие места. Впрочем, оно так и происходит.
Wednesday, January 27th, 2016 11:15 am (UTC)
Is there are an environment where sizeof(void*) is less than sizeof(size_t)?
Wednesday, January 27th, 2016 11:30 am (UTC)
I've never dealt with anything like this, but could be, could't it?
Wednesday, January 27th, 2016 11:38 am (UTC)
Stranger things happened, indeed.
Wednesday, January 27th, 2016 11:59 am (UTC)
sizeof() should return long. Problem solved.
Wednesday, January 27th, 2016 12:09 pm (UTC)
so basically when I'm calling malloc(X*Y) I need to have X*Y bytes for data + X*4 for pointers?

(4 depends on architecture, I guess)
Wednesday, January 27th, 2016 12:21 pm (UTC)
The following code excerpt from OpenSSH 3.3 demonstrates a classic case of integer overflow:

nresp = packet_get_int();
if (nresp > 0) {
response = xmalloc(nresp*sizeof(char*));
for (i = 0; i < nresp; i++)
response[i] = packet_get_string(NULL);
}
If nresp has the value 1073741824 and sizeof(char*) has its typical value of 4, then the result of the operation nresp*sizeof(char*) overflows, and the argument to xmalloc() will be 0. Most malloc() implementations will happily allocate a 0-byte buffer, causing the subsequent loop iterations to overflow the heap buffer response.
Wednesday, January 27th, 2016 12:25 pm (UTC)
Thank you.
Wednesday, January 27th, 2016 02:01 pm (UTC)
и джаву тоже разрущить, оставить только лисп и haskell
Wednesday, January 27th, 2016 05:59 pm (UTC)
So why a size_t isn't 64-bit on 64-bit systems?
Wednesday, January 27th, 2016 06:24 pm (UTC)
C можно оставить: 1) для эмбеда (раньше всё железо было как эмбед, но сейчас-то...) 2) для ковыряния ядра линукса, потому что оно с нами надолго (несмотря на Erlang on Xen и тому подобные замечательные штуки), 3) для исправления секьюрити-багов, которые наоставляли поколения предыдущих C-кодеров.

Всё, что работает на современных компьютерах и серверах, должно писаться не на C. На выбор: Java/Scala/Erlang/Go/Rust/OCaml/любой другой язык с managed memory.
Wednesday, January 27th, 2016 06:24 pm (UTC)
Джава и так скоро умрёт. А си вот что-то не собирается, хотя вреда от него больше.
Wednesday, January 27th, 2016 06:25 pm (UTC)
Кто без сегфолта, пусть первый бросит в меня камень.
Page 1 of 3 << [1] [2] [3] >>