Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/string/memset_s.c
- This file was added.
/*- | |||||
* Copyright (c) 2017 Juniper Networks. All rights reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in the | |||||
* documentation and/or other materials provided with the distribution. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
*/ | |||||
#include <sys/cdefs.h> | |||||
__FBSDID("$FreeBSD$"); | |||||
#include <errno.h> | |||||
#include <stddef.h> | |||||
#include <stdint.h> | |||||
#include <string.h> | |||||
void __throw_constraint_handler_s(const char * restrict msg, | |||||
errno_t error); | |||||
kib: extern keyword is excessive. | |||||
/* ISO/IEC 9899:2011 K.3.7.4.1 */ | |||||
Not Done Inline ActionsThis function violates every single rule in style(9). It should start as errno_t memset_s() { errno_t ret; rsize_t lim; unsigned char v; ... *dst; ret = EINVAL; kib: This function violates every single rule in style(9). It should start as
```
errno_t
memset_s… | |||||
errno_t | |||||
memset_s(void *s, rsize_t smax, int c, rsize_t n) | |||||
Not Done Inline ActionsToo many (). If there are runtime constraint violations, corresponding handlers should be called, am I right ? I.e. libc must grow registration interfaces as well. kib: Too many ().
If there are runtime constraint violations, corresponding handlers should be… | |||||
{ | |||||
errno_t ret; | |||||
Not Done Inline ActionsThis function still violates almost all style rules. No initialization in local declaration. Use single space to separate type name from the variable name. Same for all locals in this function. kib: This function still violates almost all style rules.
No initialization in local declaration. | |||||
rsize_t lim; | |||||
kibUnsubmitted Not Done Inline ActionsStill tab instead of space. kib: Still tab instead of space. | |||||
unsigned char v; | |||||
Not Done Inline ActionsStill tab. kib: Still tab. | |||||
Not Done Inline ActionsNot sure what you mean here trix_juniper.net: Not sure what you mean here | |||||
Not Done Inline ActionsI mean that the type and variable names are still separated by tab and not space. kib: I mean that the type and variable names are still separated by tab and not space. | |||||
volatile unsigned char *dst; | |||||
Not Done Inline ActionsBlank line before this one. kib: Blank line before this one. | |||||
ret = EINVAL; | |||||
lim = smax; | |||||
v = (unsigned char)c; | |||||
dst = (unsigned char *)s; | |||||
Not Done Inline Actionsreturn (ret); kib: return (ret); | |||||
Not Done Inline Actions4-spaces indent for continuation line. kib: 4-spaces indent for continuation line. | |||||
if (s == NULL) { | |||||
__throw_constraint_handler_s("memset_s : s is NULL", ret); | |||||
} else if (smax > RSIZE_MAX) { | |||||
__throw_constraint_handler_s("memset_s : smax > RSIZE_MAX", | |||||
ret); | |||||
} else if (n > RSIZE_MAX) { | |||||
__throw_constraint_handler_s("memset_s : n > RSIZE_MAX", ret); | |||||
} else { | |||||
if (n < smax) | |||||
lim = n; | |||||
Not Done Inline Actionsreturn (ret); kib: return (ret); | |||||
while (lim > 0) | |||||
dst[--lim] = v; | |||||
ret = 0; | |||||
} | |||||
return (ret); | |||||
} |
extern keyword is excessive.