Path: csiph.com!news.swapon.de!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: size_t vs long. Date: Tue, 29 Nov 2022 13:47:18 -0800 Organization: None to speak of Lines: 38 Message-ID: <87pmd5juvt.fsf@nosuchdomain.example.com> References: <5a71fdad-b7d6-4b4a-a3ee-c5a9beb75d28n@googlegroups.com> <3cd9fa14-f717-40b6-a430-5b6f609fcdc7n@googlegroups.com> <1b4juk47wa.fsf@pfeifferfamily.net> <0a801acb-1c1d-4216-894a-aa11ad307934n@googlegroups.com> <87tu2hk4fa.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="cc7f8f5b661184005b827a5d1852c190"; logging-data="2472321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IRjru/fsCa15L7JUgjllx" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:9gLu2bp2G2ziw5mCwpshhRfoQnI= sha1:r2zlJpgIhPgEXJjUvvkZqIKmO1g= Xref: csiph.com comp.lang.c:168391 scott@slp53.sl.home (Scott Lurndal) writes: [...] > At one of the X/Open meetings mid 90s, we considered adding EFAULT > as a return code from memcpy/memset/memmove and the str* > functions, but decided the overhead required to support it > was excessive at the time (e.g. each call to mem* or str* > functions would establish a signal handler for SIGSEGV > and SIGBUS, and restore the original handler(s) before > returning). > > That said, SuS/Posix does allow an implementation to return > error codes that are not explicitly defined by the specification, > so an implementation can add that capability if needed. memcpy() returns a void*. C specifies that it returns a pointer to the destination object. POSIX says pretty much the same thing: https://pubs.opengroup.org/onlinepubs/9699919799/functions/memcpy.html The memcpy() function shall return s1; no return value is reserved to indicate an error. ... No errors are defined. ... The memcpy() function does not check for the overflow of the receiving memory area. Of course it could return anything it likes in cases of undefined behavior, but neither C nor POSIX says so explicitly. Was the proposal was to set errno? Setting errno and returning a null pointer could make sense. (Returning EFAULT from a void* function would be awkward.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for XCOM Labs void Void(void) { Void(); } /* The recursive call of the void */