[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] src/sort.c: assert on temp.text before calling memcpy()
From: |
Pádraig Brady |
Subject: |
Re: [PATCH] src/sort.c: assert on temp.text before calling memcpy() |
Date: |
Wed, 06 Jan 2010 12:15:02 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 |
On 06/01/10 11:16, Kovarththanan Rajaratnam wrote:
Pádraig Brady wrote:
That looks wrong.
Should memcpy() be marked as nonnull as the length can be 0?
That doesn't matter:
C99 7.21.1#2 "Where an argument declared as size_t n specifies
the length of the array for a function, n can have the value
zero on a call to that function. Unless explicitly stated
otherwise in the description of a particular function in this
subclause, pointer arguments on such a call shall still have
valid values, as described in 7.1.4. On such a call, a
function that locates a character finds no occurrence, a
function that compares two character sequences returns zero,
and a function that copies characters copies zero characters."
Seems like a silly memcpy implementation that would touch
the pointers when n==0
In any case we don't want to be asserting in such cases,
rather just doing:
if (temp.text)
memcpy (...)
From what I could gather all paths seem to lead to a temp.text which
is non null. That is why I preferred the assert(). Is this assumption
incorrect?
Having checked the code, I don't think it's incorrect
as line->length is >=1, though why couldn't clang figure that out?
Will we have to be putting asserts before loads of these
nonnull functions now?
cheers,
Pádraig