This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit b64c03028e185005143f09d089beb629a09785ca Author: Marco Casaroli <[email protected]> AuthorDate: Fri Oct 16 00:13:11 2026 +0200 libs/libc: Fix the nxstyle errors in 113 files. Fix the indentation, blank lines and comment layout that nxstyle reports, so that a later change to one of these files passes the CI check, which checks every changed file whole. Whitespace and comments only. The C tokens of each file are the same as before. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- libs/libc/dirent/lib_readdirr.c | 1 + libs/libc/elf/elf_sections.c | 1 + libs/libc/hex2bin/lib_hex2bin.c | 274 ++++----- libs/libc/locale/lib_catalog.c | 40 +- libs/libc/locale/lib_gettext.c | 1 + libs/libc/lzf/lzf.h | 3 +- libs/libc/lzf/lzf_c.c | 1 + libs/libc/lzf/lzf_d.c | 3 +- libs/libc/machine/arch_libc.c | 4 +- libs/libc/machine/arm/arch_crc32.c | 8 + libs/libc/machine/arm64/arch_mcount.c | 1 + libs/libc/machine/mips/arch_elf.c | 2 + libs/libc/machine/risc-v/arch_elf.c | 6 + libs/libc/machine/sim/arch_elf.c | 18 +- libs/libc/machine/sparc/arch_elf.c | 44 +- libs/libc/machine/x86/arch_elf.c | 16 +- libs/libc/machine/xtensa/arch_elf.c | 99 ++-- libs/libc/misc/lib_backtrace.c | 4 + libs/libc/misc/lib_crc32.c | 1 + libs/libc/misc/lib_envpath.c | 2 +- libs/libc/misc/lib_fdcheck.c | 2 + libs/libc/misc/lib_fdsan.c | 1 + libs/libc/misc/lib_glob.c | 6 + libs/libc/misc/lib_note.c | 1 + libs/libc/misc/lib_tempbuffer.c | 2 + libs/libc/net/lib_base64.c | 18 +- libs/libc/net/lib_etheraton.c | 1 + libs/libc/net/lib_etherntoa.c | 1 + libs/libc/net/lib_freeifaddrs.c | 1 + libs/libc/net/lib_indextoname.c | 2 + libs/libc/net/lib_inetnetwork.c | 1 + libs/libc/net/lib_inetntoa.c | 2 + libs/libc/net/lib_inetntop.c | 18 +- libs/libc/net/lib_nametoindex.c | 2 + libs/libc/netdb/lib_dnscache.c | 1 + libs/libc/netdb/lib_dnsnotify.c | 1 + libs/libc/netdb/lib_dnsquery.c | 2 + libs/libc/netdb/lib_getaddrinfo.c | 2 + libs/libc/netdb/lib_gethostbyaddrr.c | 1 + libs/libc/netdb/lib_proto.c | 3 + libs/libc/netdb/lib_protor.c | 3 + libs/libc/obstack/lib_obstack_copy.c | 2 + libs/libc/obstack/lib_obstack_finish.c | 1 + libs/libc/obstack/lib_obstack_make_room.c | 1 + libs/libc/pthread/pthread_barrierwait.c | 1 + libs/libc/pthread/pthread_kill.c | 1 + libs/libc/pwd/lib_find_pwdfile.c | 3 + libs/libc/pwd/lib_getpwbuf.c | 1 + libs/libc/pwd/lib_getpwent.c | 1 + libs/libc/pwd/lib_getspnam.c | 1 + libs/libc/sched/task_gettid.c | 1 + libs/libc/search/hash_func.c | 3 +- libs/libc/spawn/lib_psfa_dump.c | 64 +-- libs/libc/stdio/lib_fmemopen.c | 3 + libs/libc/stdio/lib_fopen.c | 4 +- libs/libc/stdio/lib_fputwc.c | 1 + libs/libc/stdio/lib_fputws.c | 1 + libs/libc/stdio/lib_ftello.c | 1 + libs/libc/stdio/lib_getchar.c | 2 + libs/libc/stdio/lib_libdgets.c | 1 + libs/libc/stdio/lib_putchar.c | 2 + libs/libc/stdio/lib_puts.c | 1 + libs/libc/stdio/lib_putwc.c | 1 + libs/libc/stdio/lib_setvbuf.c | 6 +- libs/libc/stdlib/lib_arc4random.c | 1 + libs/libc/stdlib/lib_ptsname.c | 1 + libs/libc/stdlib/lib_strtold.c | 12 +- libs/libc/stream/lib_blkoutstream.c | 1 + libs/libc/stream/lib_fileinstream.c | 1 + libs/libc/stream/lib_fileoutstream.c | 1 + libs/libc/stream/lib_lowoutstream.c | 1 + libs/libc/stream/lib_memoutstream.c | 1 + libs/libc/stream/lib_mtdoutstream.c | 1 + libs/libc/stream/lib_mtdsostream.c | 1 + libs/libc/stream/lib_rawoutstream.c | 1 + libs/libc/stream/lib_syslograwstream.c | 10 +- libs/libc/string/lib_bsdmemccpy.c | 2 + libs/libc/string/lib_bsdstrcat.c | 1 + libs/libc/string/lib_memcpy.c | 1 + libs/libc/string/lib_memmem.c | 74 +-- libs/libc/string/lib_strcasecmp.c | 1 + libs/libc/string/lib_strcmp.c | 1 + libs/libc/string/lib_strcpy.c | 1 + libs/libc/string/lib_strcspn.c | 1 + libs/libc/string/lib_strlen.c | 1 + libs/libc/string/lib_strncasecmp.c | 1 + libs/libc/string/lib_strncmp.c | 1 + libs/libc/string/lib_strnlen.c | 1 + libs/libc/string/lib_strsignal.c | 80 +-- libs/libc/string/lib_strspn.c | 1 + libs/libc/string/lib_strxfrm.c | 1 + libs/libc/string/lib_vikmemcpy.c | 48 +- libs/libc/termios/lib_isatty.c | 1 + libs/libc/time/lib_asctime.c | 1 + libs/libc/time/lib_daysbeforemonth.c | 1 + libs/libc/time/lib_localtime.c | 129 +++-- libs/libc/time/lib_strftime.c | 889 +++++++++++++++--------------- libs/libc/unistd/lib_confstr.c | 6 +- libs/libc/unistd/lib_crypt_r.c | 1 + libs/libc/unistd/lib_daemon.c | 2 + libs/libc/unistd/lib_getopt_common.c | 13 +- libs/libc/unistd/lib_getoptargp.c | 1 + libs/libc/unistd/lib_getopterrp.c | 1 + libs/libc/unistd/lib_getoptindp.c | 1 + libs/libc/unistd/lib_getoptoptp.c | 1 + libs/libc/unistd/lib_ulimit.c | 2 + libs/libc/userfs/lib_userfs.c | 1 + libs/libc/wchar/lib_wcscpy.c | 1 + libs/libc/wchar/lib_wcsrchr.c | 1 + libs/libc/wchar/lib_wcsspn.c | 1 + libs/libc/wchar/lib_wcswidth.c | 1 + libs/libc/wctype/lib_iswctype.c | 52 +- libs/libc/wctype/lib_wctype.c | 174 +++--- 113 files changed, 1197 insertions(+), 1034 deletions(-) diff --git a/libs/libc/dirent/lib_readdirr.c b/libs/libc/dirent/lib_readdirr.c index e7cbf472d32..ba4ff3eb6c5 100644 --- a/libs/libc/dirent/lib_readdirr.c +++ b/libs/libc/dirent/lib_readdirr.c @@ -81,6 +81,7 @@ int readdir_r(FAR DIR *dirp, FAR struct dirent *entry, if (!tmp) { int error = get_errno(); + if (!error) { if (result) diff --git a/libs/libc/elf/elf_sections.c b/libs/libc/elf/elf_sections.c index 62a7b436548..fbc4e3318c6 100644 --- a/libs/libc/elf/elf_sections.c +++ b/libs/libc/elf/elf_sections.c @@ -184,6 +184,7 @@ int libelf_findsection(FAR struct mod_loadinfo_s *loadinfo, /* Get the name of this section */ int ret = libelf_sectname(loadinfo, shdr); + if (ret < 0) { berr("ERROR: libelf_sectname failed: %d\n", ret); diff --git a/libs/libc/hex2bin/lib_hex2bin.c b/libs/libc/hex2bin/lib_hex2bin.c index 389f5ffb3e8..ff5cd6f5659 100644 --- a/libs/libc/hex2bin/lib_hex2bin.c +++ b/libs/libc/hex2bin/lib_hex2bin.c @@ -498,179 +498,187 @@ int hex2bin(FAR struct lib_instream_s *instream, switch (bin[RECTYPE_BINNDX]) { - case RECORD_DATA: /* Data */ - { - /* Swap data in place in the binary buffer as required */ - - switch (swap) - { - case HEX2BIN_NOSWAP: /* No swap, stream is the correct byte order */ - break; + case RECORD_DATA: /* Data */ + { + /* Swap data in place in the binary buffer as required */ - case HEX2BIN_SWAP16: /* Swap bytes in 16-bit values */ + switch (swap) { - if ((bytecount & 1) != 0) - { - lerr("Line %d ERROR: Byte count %d is not a multiple " - "of 2\n", - lineno, bytecount); - goto errout_with_einval; - } + case HEX2BIN_NOSWAP: - /* Do the byte swap */ + /* No swap, stream is the correct byte order */ - hex2bin_swap16(&bin[DATA_BINNDX], bytecount); - } - break; + break; - case HEX2BIN_SWAP32: /* Swap bytes in 32-bit values */ - { - if ((bytecount & 3) != 0) + case HEX2BIN_SWAP16: /* Swap bytes in 16-bit values */ { - lerr("Line %d ERROR: Byte count %d is not a multiple " - "of 4\n", - lineno, bytecount); - goto errout_with_einval; + if ((bytecount & 1) != 0) + { + lerr( + "Line %d ERROR: Byte count %d is not a multiple " + "of 2\n", + lineno, bytecount); + goto errout_with_einval; + } + + /* Do the byte swap */ + + hex2bin_swap16(&bin[DATA_BINNDX], bytecount); } + break; - /* Do the byte swap */ + case HEX2BIN_SWAP32: /* Swap bytes in 32-bit values */ + { + if ((bytecount & 3) != 0) + { + lerr( + "Line %d ERROR: Byte count %d is not a multiple " + "of 4\n", + lineno, bytecount); + goto errout_with_einval; + } + + /* Do the byte swap */ + + hex2bin_swap32(&bin[DATA_BINNDX], bytecount); + } + break; - hex2bin_swap32(&bin[DATA_BINNDX], bytecount); + default: + { + lerr("ERROR: Invalid swap argument: %d\n", swap); + goto errout_with_einval; + } } - break; - default: + /* Get and verify the full 32-bit address */ + + address = extension + (unsigned long)address16; + endaddr = address + bytecount; + + if (address < baseaddr || + (endpaddr != 0 && endaddr >= endpaddr)) { - lerr("ERROR: Invalid swap argument: %d\n", swap); + lerr("Line %d ERROR: Extended address %08lx is out of " + "range\n", + lineno, (unsigned long)address); goto errout_with_einval; } - } - /* Get and verify the full 32-bit address */ + /* Seek to the correct position in the OUT stream if we have + * made an unexpected jump in the data address. + */ - address = extension + (unsigned long)address16; - endaddr = address + bytecount; - - if (address < baseaddr || (endpaddr != 0 && endaddr >= endpaddr)) - { - lerr("Line %d ERROR: Extended address %08lx is out of " - "range\n", - lineno, (unsigned long)address); - goto errout_with_einval; - } - - /* Seek to the correct position in the OUT stream if we have - * made an unexpected jump in the data address. - */ + if (address != expected) + { + off_t pos = lib_stream_seek(outstream, + address - baseaddr, SEEK_SET); - if (address != expected) - { - off_t pos = lib_stream_seek(outstream, - address - baseaddr, SEEK_SET); - if (pos == (off_t)-1) - { - lerr("Line %u ERROR: Seek to address %08lu failed\n", - lineno, (unsigned long)address); - ret = -ESPIPE; - goto errout_with_buffers; - } - } + if (pos == (off_t)-1) + { + lerr("Line %u ERROR: Seek to address %08lu failed\n", + lineno, (unsigned long)address); + ret = -ESPIPE; + goto errout_with_buffers; + } + } - /* Transfer data to the OUT stream */ + /* Transfer data to the OUT stream */ - writedata(outstream, &bin[DATA_BINNDX], bytecount); + writedata(outstream, &bin[DATA_BINNDX], bytecount); - /* This is the next data address that we expect to see */ + /* This is the next data address that we expect to see */ - expected = address + bytecount; - } - break; + expected = address + bytecount; + } + break; - case RECORD_EOF: /* End of file */ + case RECORD_EOF: /* End of file */ - /* End Of File record. Must occur exactly once per file in the - * last line of the file. The byte count is 00 and the data field - * is empty. Usually the address field is also 0000. - */ + /* End Of File record. Must occur exactly once per file in the + * last line of the file. The byte count is 00 and the data field + * is empty. Usually the address field is also 0000. + */ - if (bytecount == 0) - { - ret = OK; - goto exit_with_buffers; - } + if (bytecount == 0) + { + ret = OK; + goto exit_with_buffers; + } - lerr("Line %u ERROR: Nonzero bytecount %d in EOF\n", - lineno, bytecount); - goto errout_with_einval; + lerr("Line %u ERROR: Nonzero bytecount %d in EOF\n", + lineno, bytecount); + goto errout_with_einval; - case RECORD_EXT_SEGADDR: /* Extended segment address record */ + case RECORD_EXT_SEGADDR: /* Extended segment address record */ - /* The address specified by the data field is multiplied by 16 - * (shifted 4 bits left) and added to the subsequent data record - * addresses. This allows addressing of up to a megabyte of - * address space. The address field of this record has to be - * 0000, the byte count is 02 (the segment is 16-bit). The - * least significant hex digit of the segment address is always - * 0. - */ + /* The address specified by the data field is multiplied by 16 + * (shifted 4 bits left) and added to the subsequent data record + * addresses. This allows addressing of up to a megabyte of + * address space. The address field of this record has to be + * 0000, the byte count is 02 (the segment is 16-bit). The + * least significant hex digit of the segment address is always + * 0. + */ - if (bytecount != 2 || address16 != 0 || bin[DATA_BINNDX + 1] != 0) - { - lerr("Line %u ERROR: Invalid segment address\n", lineno); - lerr(" bytecount=%d address=%04x segment=%02x%02x\n", - bytecount, address16, bin[DATA_BINNDX], - bin[DATA_BINNDX + 1]); - goto errout_with_einval; - } + if (bytecount != 2 || address16 != 0 || + bin[DATA_BINNDX + 1] != 0) + { + lerr("Line %u ERROR: Invalid segment address\n", lineno); + lerr(" bytecount=%d address=%04x segment=%02x%02x\n", + bytecount, address16, bin[DATA_BINNDX], + bin[DATA_BINNDX + 1]); + goto errout_with_einval; + } - extension = (unsigned long)bin[DATA_BINNDX] << 12; - break; + extension = (unsigned long)bin[DATA_BINNDX] << 12; + break; - case RECORD_START_SEGADDR: /* Start segment address record */ + case RECORD_START_SEGADDR: /* Start segment address record */ - /* For 80x86 processors, it specifies the initial content of - * the CS:IP registers. The address field is 0000, the byte - * count is 04, the first two bytes are the CS value, the - * latter two are the IP value. - */ + /* For 80x86 processors, it specifies the initial content of + * the CS:IP registers. The address field is 0000, the byte + * count is 04, the first two bytes are the CS value, the + * latter two are the IP value. + */ - break; + break; - case RECORD_EXT_LINADDR: /* Extended linear address record */ + case RECORD_EXT_LINADDR: /* Extended linear address record */ - /* The address field is 0000, the byte count is 02. The two - * data bytes (two hex digit pairs in big endian order) - * represent the upper 16 bits of the 32 bit address for - * all subsequent 00 type records until the next 04 type - * record comes. If there is not a 04 type record, the - * upper 16 bits default to 0000. To get the absolute - * address for subsequent 00 type records, the address - * specified by the data field of the most recent 04 record - * is added to the 00 record addresses. - */ + /* The address field is 0000, the byte count is 02. The two + * data bytes (two hex digit pairs in big endian order) + * represent the upper 16 bits of the 32 bit address for + * all subsequent 00 type records until the next 04 type + * record comes. If there is not a 04 type record, the + * upper 16 bits default to 0000. To get the absolute + * address for subsequent 00 type records, the address + * specified by the data field of the most recent 04 record + * is added to the 00 record addresses. + */ - if (bytecount != 2 || address16 != 0) - { - lerr("Line %u ERROR: Invalid linear address\n", lineno); - lerr(" bytecount=%d address=%04x\n", bytecount, address16); - goto errout_with_einval; - } + if (bytecount != 2 || address16 != 0) + { + lerr("Line %u ERROR: Invalid linear address\n", lineno); + lerr(" bytecount=%d address=%04x\n", bytecount, address16); + goto errout_with_einval; + } - extension = (unsigned long)bin[DATA_BINNDX] << 24 | - (unsigned long)bin[DATA_BINNDX + 1] << 16; - break; + extension = (unsigned long)bin[DATA_BINNDX] << 24 | + (unsigned long)bin[DATA_BINNDX + 1] << 16; + break; - case RECORD_START_LINADDR: /* Start linear address record */ + case RECORD_START_LINADDR: /* Start linear address record */ - /* The address field is 0000, the byte count is 04. The 4 - * data bytes represent the 32-bit value loaded into the EIP - * register of the 80386 and higher CPU. - */ + /* The address field is 0000, the byte count is 04. The 4 + * data bytes represent the 32-bit value loaded into the EIP + * register of the 80386 and higher CPU. + */ - break; + break; - default: - break; + default: + break; } } diff --git a/libs/libc/locale/lib_catalog.c b/libs/libc/locale/lib_catalog.c index 59ca4f75fa6..cb8d0facccb 100644 --- a/libs/libc/locale/lib_catalog.c +++ b/libs/libc/locale/lib_catalog.c @@ -279,26 +279,26 @@ nl_catd catopen(FAR const char *name, int oflag) i += l; } - if (*z) - { - z++; - } - - if (*p != ':' && *p != '\0') - { - continue; - } - - /* Leading : or :: in NLSPATH is same as %N */ - - buf[i] = 0; - catd = catmap(i ? buf : name); - if (catd != MAP_FAILED) - { - lib_put_pathbuffer(buf); - return catd; - } - } + if (*z) + { + z++; + } + + if (*p != ':' && *p != '\0') + { + continue; + } + + /* Leading : or :: in NLSPATH is same as %N */ + + buf[i] = 0; + catd = catmap(i ? buf : name); + if (catd != MAP_FAILED) + { + lib_put_pathbuffer(buf); + return catd; + } + } lib_put_pathbuffer(buf); set_errno(ENOENT); diff --git a/libs/libc/locale/lib_gettext.c b/libs/libc/locale/lib_gettext.c index b61e63c424d..c4de8d90e54 100644 --- a/libs/libc/locale/lib_gettext.c +++ b/libs/libc/locale/lib_gettext.c @@ -672,6 +672,7 @@ FAR char *dcngettext(FAR const char *domainname, if (msgid2 && mofile->nplurals) { unsigned long plural = eval(mofile->plural_rule, n); + if (plural >= mofile->nplurals) { return notrans; diff --git a/libs/libc/lzf/lzf.h b/libs/libc/lzf/lzf.h index fa911df6845..e3dda7421cc 100644 --- a/libs/libc/lzf/lzf.h +++ b/libs/libc/lzf/lzf.h @@ -2,7 +2,8 @@ * libs/libc/lzf/lzf.h * * SPDX-License-Identifier: BSD-2-Clause - * SPDX-FileCopyrightText: 2000-2007 Marc Alexander Lehmann <[email protected]> + * SPDX-FileCopyrightText: 2000-2007 Marc Alexander Lehmann + * <[email protected]> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/libs/libc/lzf/lzf_c.c b/libs/libc/lzf/lzf_c.c index 83508a1cf2f..5a552fa3e89 100644 --- a/libs/libc/lzf/lzf_c.c +++ b/libs/libc/lzf/lzf_c.c @@ -192,6 +192,7 @@ size_t lzf_compress(FAR const void *const in_data, unsigned int len = 2; unsigned int maxlen = in_end - ip - len; + maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; /* First a faster conservative test */ diff --git a/libs/libc/lzf/lzf_d.c b/libs/libc/lzf/lzf_d.c index 5bd34812cec..edc83fca50a 100644 --- a/libs/libc/lzf/lzf_d.c +++ b/libs/libc/lzf/lzf_d.c @@ -2,7 +2,8 @@ * libs/libc/lzf/lzf_d.c * * SPDX-License-Identifier: BSD-2-Clause - * SPDX-FileCopyrightText: 2000-2010 Marc Alexander Lehmann <[email protected]> + * SPDX-FileCopyrightText: 2000-2010 Marc Alexander Lehmann + * <[email protected]> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/libs/libc/machine/arch_libc.c b/libs/libc/machine/arch_libc.c index aaad3f83fdb..cbda598ff89 100644 --- a/libs/libc/machine/arch_libc.c +++ b/libs/libc/machine/arch_libc.c @@ -141,8 +141,8 @@ int memcmp(FAR const void *s1, FAR const void *s2, size_t n) { # ifdef CONFIG_MM_KASAN_INSTRUMENT # ifndef CONFIG_MM_KASAN_DISABLE_READS_CHECK - __asan_loadN((FAR void *)s1, n); - __asan_loadN((FAR void *)s2, n); + __asan_loadN((FAR void *)s1, n); + __asan_loadN((FAR void *)s2, n); # endif # endif return ARCH_LIBCFUN(memcmp)(s1, s2, n); diff --git a/libs/libc/machine/arm/arch_crc32.c b/libs/libc/machine/arm/arch_crc32.c index 2b0c7bcd6dc..ea9f43097e5 100644 --- a/libs/libc/machine/arm/arch_crc32.c +++ b/libs/libc/machine/arm/arch_crc32.c @@ -47,12 +47,14 @@ uint32_t crc32part(FAR const uint8_t *src, size_t len, uint32_t crc32val) for (; (i + 8) <= len; i += 8) { uint64_t data = *(uint64_t *)(src + i); + crc32val = __crc32d(crc32val, data); } if (i + 4 <= len) { uint32_t data = *(uint32_t *)(src + i); + crc32val = __crc32w(crc32val, data); i += 4; } @@ -60,6 +62,7 @@ uint32_t crc32part(FAR const uint8_t *src, size_t len, uint32_t crc32val) if (i + 2 <= len) { uint16_t data = *(uint16_t *)(src + i); + crc32val = __crc32h(crc32val, data); i += 2; } @@ -67,6 +70,7 @@ uint32_t crc32part(FAR const uint8_t *src, size_t len, uint32_t crc32val) if (i < len) { uint8_t data = *(uint8_t *)(src + i); + crc32val = __crc32b(crc32val, data); } @@ -88,12 +92,14 @@ uint32_t crc32part_c(FAR const uint8_t *src, size_t len, uint32_t crc32val) for (; (i + 8) <= len; i += 8) { uint64_t data = *(uint64_t *)(src + i); + crc32val = __crc32cd(crc32val, data); } if (i + 4 <= len) { uint32_t data = *(uint32_t *)(src + i); + crc32val = __crc32cw(crc32val, data); i += 4; } @@ -101,6 +107,7 @@ uint32_t crc32part_c(FAR const uint8_t *src, size_t len, uint32_t crc32val) if (i + 2 <= len) { uint16_t data = *(uint16_t *)(src + i); + crc32val = __crc32ch(crc32val, data); i += 2; } @@ -108,6 +115,7 @@ uint32_t crc32part_c(FAR const uint8_t *src, size_t len, uint32_t crc32val) if (i < len) { uint8_t data = *(uint8_t *)(src + i); + crc32val = __crc32cb(crc32val, data); } diff --git a/libs/libc/machine/arm64/arch_mcount.c b/libs/libc/machine/arm64/arch_mcount.c index be7bc7c4da8..f88a4566791 100644 --- a/libs/libc/machine/arm64/arch_mcount.c +++ b/libs/libc/machine/arm64/arch_mcount.c @@ -31,6 +31,7 @@ static inline noinstrument_function void *strip_pac(void *p) { register void *ra asm ("x30") = (p); + asm ("hint 7 // xpaclri" : "+r"(ra)); return ra; } diff --git a/libs/libc/machine/mips/arch_elf.c b/libs/libc/machine/mips/arch_elf.c index 198dfdb9086..377bedf636e 100644 --- a/libs/libc/machine/mips/arch_elf.c +++ b/libs/libc/machine/mips/arch_elf.c @@ -151,6 +151,7 @@ int up_relocate(const Elf_Rel *rel, const Elf_Sym *sym, uintptr_t addr, { Elf_Addr a = *p & 0x03ffffff; Elf_Addr val = ((a << 2) | ((Elf_Addr)p & 0xf0000000)) + s; + val = (val >> 2) & 0x03ffffff; *p &= 0xfc000000; *p |= val; @@ -177,6 +178,7 @@ int up_relocate(const Elf_Rel *rel, const Elf_Sym *sym, uintptr_t addr, int16_t a = *p; Elf_Addr ahl = (data->ahi << 16) + a; Elf32_Addr iword = *p & 0xffff0000; + iword |= (uint16_t)(ahl + s); *p = iword; diff --git a/libs/libc/machine/risc-v/arch_elf.c b/libs/libc/machine/risc-v/arch_elf.c index d2a98481b74..5b02617dfd6 100644 --- a/libs/libc/machine/risc-v/arch_elf.c +++ b/libs/libc/machine/risc-v/arch_elf.c @@ -119,6 +119,7 @@ static const char *_get_rname(int type) static uint32_t _get_val(uint16_t *addr) { uint32_t ret; + ret = *addr | (*(addr + 1)) << 16; return ret; } @@ -136,6 +137,7 @@ static void _set_val(uint16_t *addr, uint32_t val) static void _add_val(uint16_t *addr, uint32_t val) { uint32_t cur = _get_val(addr); + _set_val(addr, cur + val); } @@ -282,6 +284,7 @@ static inline bool _valid_hi20_imm(long imm_hi) long hi = imm_hi & ((1 << 20) - 1); /* 32-bit signed value */ long sign = -((imm_hi >> 19) & 1); /* 32-bit sign value */ + hi = ((hi << 12) | sign << 32) >> 12; /* 32-bit sign extend */ /* If the values do not match, the immediate is invalid */ @@ -613,6 +616,7 @@ int up_relocateadd(const Elf_Rela *rel, const Elf_Sym *sym, long imm_hi; long imm_lo; + _calc_imm(offset, &imm_hi, &imm_lo); if (!_valid_hi20_imm(imm_hi)) @@ -644,6 +648,7 @@ int up_relocateadd(const Elf_Rela *rel, const Elf_Sym *sym, long imm_hi; long imm_lo; + _calc_imm(offset, &imm_hi, &imm_lo); insn = (insn & 0x000fffff) | (imm_lo << 20); @@ -668,6 +673,7 @@ int up_relocateadd(const Elf_Rela *rel, const Elf_Sym *sym, long imm_hi; long imm_lo; + _calc_imm(offset, &imm_hi, &imm_lo); uint32_t val = diff --git a/libs/libc/machine/sim/arch_elf.c b/libs/libc/machine/sim/arch_elf.c index 9ddd94710bf..51888bc5c21 100644 --- a/libs/libc/machine/sim/arch_elf.c +++ b/libs/libc/machine/sim/arch_elf.c @@ -105,17 +105,17 @@ int up_relocate(const Elf32_Rel *rel, const Elf32_Sym *sym, uintptr_t addr, switch (ELF32_R_TYPE(rel->r_info)) { - case R_386_32: - *ptr += sym->st_value; - break; + case R_386_32: + *ptr += sym->st_value; + break; - case R_386_PC32: - *ptr += sym->st_value - (uint32_t)((uintptr_t)ptr); - break; + case R_386_PC32: + *ptr += sym->st_value - (uint32_t)((uintptr_t)ptr); + break; - default: - berr("ERROR: Unsupported type %u\n", ELF32_R_TYPE(rel->r_info)); - return -EINVAL; + default: + berr("ERROR: Unsupported type %u\n", ELF32_R_TYPE(rel->r_info)); + return -EINVAL; } return OK; diff --git a/libs/libc/machine/sparc/arch_elf.c b/libs/libc/machine/sparc/arch_elf.c index 2c059a89b00..2bf122d014e 100644 --- a/libs/libc/machine/sparc/arch_elf.c +++ b/libs/libc/machine/sparc/arch_elf.c @@ -169,84 +169,84 @@ int up_relocateadd(const Elf32_Rela *rel, const Elf32_Sym *sym, switch (relotype) { - case R_SPARC_NONE: - break; - case R_SPARC_8: + case R_SPARC_NONE: + break; + case R_SPARC_8: (*(uint8_t *)addr) = (uint8_t)value; break; - case R_SPARC_16: + case R_SPARC_16: (*(uint16_t *)addr) = (uint16_t)value; break; - case R_SPARC_32: + case R_SPARC_32: (*(uint32_t *)addr) = value; break; - case R_SPARC_DISP8: - case R_SPARC_DISP16: - case R_SPARC_DISP32: + case R_SPARC_DISP8: + case R_SPARC_DISP16: + case R_SPARC_DISP32: (*(uint32_t *)addr) = value - addr; break; - case R_SPARC_WDISP30: + case R_SPARC_WDISP30: value -= addr; (*(uint32_t *)addr) &= (~0x3fffffff); (*(uint32_t *)addr) |= (value >> 2) & 0x3fffffff; break; - case R_SPARC_WDISP22: + case R_SPARC_WDISP22: value -= addr; (*(uint32_t *)addr) &= (~0x3fffff); (*(uint32_t *)addr) |= (value >> 2) & 0x3fffff; break; - case R_SPARC_HI22: + case R_SPARC_HI22: (*(uint32_t *)addr) &= (~0x3fffff); (*(uint32_t *)addr) |= (value >> 10) & 0x3fffff; break; - case R_SPARC_22: + case R_SPARC_22: (*(uint32_t *)addr) &= (~0x3fffff); (*(uint32_t *)addr) |= value & 0x3fffff; break; - case R_SPARC_13: + case R_SPARC_13: (*(uint32_t *)addr) &= (~0x1ffff); (*(uint32_t *)addr) |= value & 0x1ffff; break; - case R_SPARC_LO10: + case R_SPARC_LO10: (*(uint32_t *)addr) &= (~0x3ff); (*(uint32_t *)addr) |= value & 0x3ff; break; - case R_SPARC_PC10: + case R_SPARC_PC10: value -= addr; (*(uint32_t *)addr) &= (~0x3ff); (*(uint32_t *)addr) |= value & 0x3ff; break; - case R_SPARC_PC22: + case R_SPARC_PC22: value -= addr; (*(uint32_t *)addr) &= (~0x3fffff); (*(uint32_t *)addr) |= (value >> 10) & 0x3fffff; break; - case R_SPARC_UA32: - case R_SPARC_GLOB_DAT: + case R_SPARC_UA32: + case R_SPARC_GLOB_DAT: (*(uint32_t *)addr) = value; break; - case R_SPARC_JMP_SLOT: + case R_SPARC_JMP_SLOT: (*(uint32_t *)(addr + 1)) = OPCODE_SETHI_G1 | ((value >> 10) & 0x3fffff); (*(uint32_t *)(addr + 2)) = OPCODE_JMP_G1 | (value & 0x3ff); break; - default: - berr("ERROR: RELA relocation %u not supported\n", relotype); - return -EINVAL; + default: + berr("ERROR: RELA relocation %u not supported\n", relotype); + return -EINVAL; } return OK; diff --git a/libs/libc/machine/x86/arch_elf.c b/libs/libc/machine/x86/arch_elf.c index b488b2c2ac0..4cdb70b5df0 100644 --- a/libs/libc/machine/x86/arch_elf.c +++ b/libs/libc/machine/x86/arch_elf.c @@ -113,16 +113,16 @@ int up_relocate(const Elf32_Rel *rel, const Elf32_Sym *sym, uintptr_t addr, switch (ELF32_R_TYPE(rel->r_info)) { - case R_386_32: - *ptr += sym->st_value; - break; + case R_386_32: + *ptr += sym->st_value; + break; - case R_386_PC32: - *ptr += sym->st_value - (uint32_t)ptr; - break; + case R_386_PC32: + *ptr += sym->st_value - (uint32_t)ptr; + break; - default: - return -EINVAL; + default: + return -EINVAL; } return OK; diff --git a/libs/libc/machine/xtensa/arch_elf.c b/libs/libc/machine/xtensa/arch_elf.c index 33d2a05fcd8..f155b9d018a 100644 --- a/libs/libc/machine/xtensa/arch_elf.c +++ b/libs/libc/machine/xtensa/arch_elf.c @@ -148,15 +148,15 @@ int up_relocate(const Elf32_Rel *rel, const Elf32_Sym *sym, uintptr_t addr, switch (relotype) { - case R_XTENSA_NONE: - { - /* No relocation */ - } - break; - - default: - berr("ERROR: Unsupported relocation: %u\n", relotype); - return -EINVAL; + case R_XTENSA_NONE: + { + /* No relocation */ + } + break; + + default: + berr("ERROR: Unsupported relocation: %u\n", relotype); + return -EINVAL; } return OK; @@ -190,49 +190,50 @@ int up_relocateadd(const Elf32_Rela *rel, const Elf32_Sym *sym, switch (relotype) { - case R_XTENSA_NONE: - break; - - case R_XTENSA_32: - (*(uint32_t *)(up_textheap_data_address((void *)addr))) += value; - break; + case R_XTENSA_NONE: + break; - case R_XTENSA_ASM_EXPAND: - bwarn("WARNING: Ignoring RELA relocation R_XTENSA_ASM_EXPAND %u\n", - relotype); - break; + case R_XTENSA_32: + (*(uint32_t *)(up_textheap_data_address((void *)addr))) += value; + break; - case R_XTENSA_SLOT0_OP: - p = (unsigned char *)up_textheap_data_address((void *)addr); - if (is_l32r(p)) - { - /* Xtensa ISA: - * L32R forms a virtual address by adding the 16-bit one-extended - * constant value encoded in the instruction word shifted left by - * two to the address of the L32R plus three with the two least - * significant bits cleared. - */ - - uintptr_t base = (addr + 3) & ~3; - uint16_t imm = (value - base) >> 2; - if (base + (0xfffc0000 | ((uint32_t)imm << 2)) != value) - { - berr("ERROR: Out of range rellocation at %p\n", p); - return -EINVAL; - } - - p[1] = imm & 0xff; - p[2] = (imm >> 8) & 0xff; - break; - } - - bwarn("WARNING: Ignoring RELA relocation R_XTENSA_SLOT0_OP %u\n", + case R_XTENSA_ASM_EXPAND: + bwarn("WARNING: Ignoring RELA relocation R_XTENSA_ASM_EXPAND %u\n", relotype); - break; - - default: - berr("ERROR: RELA relocation %u not supported\n", relotype); - return -EINVAL; + break; + + case R_XTENSA_SLOT0_OP: + p = (unsigned char *)up_textheap_data_address((void *)addr); + if (is_l32r(p)) + { + /* Xtensa ISA: + * L32R forms a virtual address by adding the 16-bit one-extended + * constant value encoded in the instruction word shifted left by + * two to the address of the L32R plus three with the two least + * significant bits cleared. + */ + + uintptr_t base = (addr + 3) & ~3; + uint16_t imm = (value - base) >> 2; + + if (base + (0xfffc0000 | ((uint32_t)imm << 2)) != value) + { + berr("ERROR: Out of range rellocation at %p\n", p); + return -EINVAL; + } + + p[1] = imm & 0xff; + p[2] = (imm >> 8) & 0xff; + break; + } + + bwarn("WARNING: Ignoring RELA relocation R_XTENSA_SLOT0_OP %u\n", + relotype); + break; + + default: + berr("ERROR: RELA relocation %u not supported\n", relotype); + return -EINVAL; } return OK; diff --git a/libs/libc/misc/lib_backtrace.c b/libs/libc/misc/lib_backtrace.c index 2ebb9be0dfc..31e74a10e20 100644 --- a/libs/libc/misc/lib_backtrace.c +++ b/libs/libc/misc/lib_backtrace.c @@ -107,6 +107,7 @@ static FAR char **backtrace_malloc(FAR void *const *buffer, int size) while (size-- > 0) { int ret = snprintf(NULL, 0, "%pS", *buffer++); + if (ret < 0) { return NULL; @@ -223,6 +224,7 @@ static int backtrace_alloc(FAR struct backtrace_pool_s *bp) static void backtrace_free(FAR struct backtrace_pool_s *bp, int index) { FAR struct backtrace_entry_s *entry = &bp->pool[index]; + sq_addlast(&entry->freenode, &bp->freelist); entry->depth = 0; } @@ -345,6 +347,7 @@ int backtrace_remove(int index) */ FAR struct backtrace_entry_s *next = &bp->pool[entry->next]; + index = entry->next; memcpy(entry, next, sizeof(struct backtrace_entry_s)); } @@ -355,6 +358,7 @@ int backtrace_remove(int index) */ int prev = bp->bucket[slot]; + while (prev >= 0) { if (bp->pool[prev].next == index) diff --git a/libs/libc/misc/lib_crc32.c b/libs/libc/misc/lib_crc32.c index e76065d2c02..82756869126 100644 --- a/libs/libc/misc/lib_crc32.c +++ b/libs/libc/misc/lib_crc32.c @@ -143,6 +143,7 @@ uint32_t crc32part(FAR const uint8_t *src, size_t len, uint32_t crc32val) for (i = 0; i < len; i++) { size_t j; + crc32val ^= src[i]; for (j = 0; j < 8; j++) { diff --git a/libs/libc/misc/lib_envpath.c b/libs/libc/misc/lib_envpath.c index aaf52139cd2..316582e9fb4 100644 --- a/libs/libc/misc/lib_envpath.c +++ b/libs/libc/misc/lib_envpath.c @@ -236,7 +236,7 @@ FAR char *envpath_next(ENVPATH_HANDLE handle, FAR const char *relpath) * continue to try the next path. */ - lib_free(fullpath); + lib_free(fullpath); } /* We will not get here */ diff --git a/libs/libc/misc/lib_fdcheck.c b/libs/libc/misc/lib_fdcheck.c index c32cb883e6d..88e56e564a5 100644 --- a/libs/libc/misc/lib_fdcheck.c +++ b/libs/libc/misc/lib_fdcheck.c @@ -78,6 +78,7 @@ int fdcheck_restore(int val) if (ret >= 0) { uint8_t tag_expect = (val >> TAG_SHIFT) & TAG_MASK; + if (tag_expect != tag_store) { ferr("tag_expect 0x%x tag_store 0x%x\n", @@ -114,6 +115,7 @@ int fdcheck_protect(int fd) uint8_t fdcheck_tag; irqstate_t flags = spin_lock_irqsave(&g_fdcheck_lock); + if ((++g_fdcheck_tag & TAG_MASK) == 0) { ++g_fdcheck_tag; diff --git a/libs/libc/misc/lib_fdsan.c b/libs/libc/misc/lib_fdsan.c index 4812ee23e83..44a349620a4 100644 --- a/libs/libc/misc/lib_fdsan.c +++ b/libs/libc/misc/lib_fdsan.c @@ -55,6 +55,7 @@ const char *android_fdsan_get_tag_type(uint64_t tag) { uint64_t high_bits; uint64_t type = tag >> 56; + switch (type) { case ANDROID_FDSAN_OWNER_TYPE_FILE: diff --git a/libs/libc/misc/lib_glob.c b/libs/libc/misc/lib_glob.c index b4d79b5bd96..9514f0da9c3 100644 --- a/libs/libc/misc/lib_glob.c +++ b/libs/libc/misc/lib_glob.c @@ -74,6 +74,7 @@ static int append(FAR struct match_s **tail, FAR const char *name, size_t len, int mark) { FAR struct match_s *new = lib_malloc(sizeof(struct match_s) + len + 1); + if (new == NULL) { return -1; @@ -234,6 +235,7 @@ static int do_glob(FAR char *buf, size_t pos, int type, FAR char *pat, */ struct stat st; + if ((flags & GLOB_MARK) && (!type || type == DT_LNK) && !stat(buf, &st)) { @@ -276,6 +278,7 @@ static int do_glob(FAR char *buf, size_t pos, int type, FAR char *pat, { FAR char *p; const int prev_index = -1; + for (p = p2; p > pat && p[prev_index] == '\\'; p--) { } @@ -383,6 +386,7 @@ static void freelist(FAR struct match_s *head) { FAR struct match_s *match; FAR struct match_s *next; + for (match = head->next; match; match = next) { next = match->next; @@ -493,6 +497,7 @@ int glob(FAR const char *pat, int flags, { FAR char **pathv = lib_realloc(g->gl_pathv, (offs + g->gl_pathc + cnt + 1) * sizeof(FAR char *)); + if (!pathv) { freelist(&head); @@ -540,6 +545,7 @@ int glob(FAR const char *pat, int flags, void globfree(FAR glob_t *g) { size_t i; + for (i = 0; i < g->gl_pathc; i++) { lib_free(g->gl_pathv[g->gl_offs + i] - offsetof(struct match_s, name)); diff --git a/libs/libc/misc/lib_note.c b/libs/libc/misc/lib_note.c index 704b274bb7c..c6da77e0269 100644 --- a/libs/libc/misc/lib_note.c +++ b/libs/libc/misc/lib_note.c @@ -40,6 +40,7 @@ void sched_note_printf_ip(uint32_t tag, uintptr_t ip, uint32_t type, ...) { va_list va; + va_start(va, type); sched_note_vprintf_ip(tag, ip, fmt, type, &va); va_end(va); diff --git a/libs/libc/misc/lib_tempbuffer.c b/libs/libc/misc/lib_tempbuffer.c index f642cffa671..1b8593e96ed 100644 --- a/libs/libc/misc/lib_tempbuffer.c +++ b/libs/libc/misc/lib_tempbuffer.c @@ -93,6 +93,7 @@ FAR char *lib_get_tempbuffer(size_t nbytes) int32_t update; int32_t free_bitmap = atomic_read(&g_tempbuffer.free_bitmap); int index = ffsl(free_bitmap) - 1; + if (index < 0 || index >= CONFIG_LIBC_MAX_TEMPBUFFER) { break; @@ -136,6 +137,7 @@ FAR char *lib_get_tempbuffer(size_t nbytes) void lib_put_tempbuffer(FAR char *buffer) { int index = (buffer - &g_tempbuffer.buffer[0][0]) / TEMP_MAX_SIZE; + if (index >= 0 && index < CONFIG_LIBC_MAX_TEMPBUFFER) { DEBUGASSERT((atomic_read(&g_tempbuffer.free_bitmap) & diff --git a/libs/libc/net/lib_base64.c b/libs/libc/net/lib_base64.c index 91a39cd95ae..4e840f85ce3 100644 --- a/libs/libc/net/lib_base64.c +++ b/libs/libc/net/lib_base64.c @@ -177,7 +177,7 @@ int b64_pton(FAR const char *src, default: return -1; } - } + } if (ch == g_pad64) { @@ -215,18 +215,18 @@ int b64_pton(FAR const char *src, } } - if (target && *target != 0) - { - return -1; - } + if (target && *target != 0) + { + return -1; + } } } else { - if (state != 0) - { - return -1; - } + if (state != 0) + { + return -1; + } } return datalen; diff --git a/libs/libc/net/lib_etheraton.c b/libs/libc/net/lib_etheraton.c index b1dd24fc20f..71d9a5dbe2a 100644 --- a/libs/libc/net/lib_etheraton.c +++ b/libs/libc/net/lib_etheraton.c @@ -131,5 +131,6 @@ FAR struct ether_addr *ether_aton_r(FAR const char *asc, FAR struct ether_addr *ether_aton(FAR const char *asc) { static struct ether_addr addr; + return ether_aton_r(asc, &addr); } diff --git a/libs/libc/net/lib_etherntoa.c b/libs/libc/net/lib_etherntoa.c index 6901b0a976f..31beaaf73af 100644 --- a/libs/libc/net/lib_etherntoa.c +++ b/libs/libc/net/lib_etherntoa.c @@ -67,5 +67,6 @@ FAR char *ether_ntoa_r(FAR const struct ether_addr *addr, FAR char *buf) FAR char *ether_ntoa(FAR const struct ether_addr *addr) { static char buffer[20]; + return ether_ntoa_r(addr, buffer); } diff --git a/libs/libc/net/lib_freeifaddrs.c b/libs/libc/net/lib_freeifaddrs.c index 36d1693d5be..65d508cd7d2 100644 --- a/libs/libc/net/lib_freeifaddrs.c +++ b/libs/libc/net/lib_freeifaddrs.c @@ -52,6 +52,7 @@ void freeifaddrs(FAR struct ifaddrs *addrs) while (addrs != NULL) { FAR struct ifaddrs *tmp = addrs; + addrs = addrs->ifa_next; lib_free(tmp); } diff --git a/libs/libc/net/lib_indextoname.c b/libs/libc/net/lib_indextoname.c index 73d04b12cc0..feec901e233 100644 --- a/libs/libc/net/lib_indextoname.c +++ b/libs/libc/net/lib_indextoname.c @@ -58,9 +58,11 @@ FAR char *if_indextoname(unsigned int ifindex, FAR char *ifname) { int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL); + if (sockfd >= 0) { struct ifreq req; + req.ifr_ifindex = ifindex; if (ioctl(sockfd, SIOCGIFNAME, (unsigned long)&req) >= 0) { diff --git a/libs/libc/net/lib_inetnetwork.c b/libs/libc/net/lib_inetnetwork.c index 5d5cba7eca4..cb6b528baaf 100644 --- a/libs/libc/net/lib_inetnetwork.c +++ b/libs/libc/net/lib_inetnetwork.c @@ -68,5 +68,6 @@ in_addr_t inet_network(FAR const char *cp) { in_addr_t t = inet_addr(cp); + return NTOHL(t); } diff --git a/libs/libc/net/lib_inetntoa.c b/libs/libc/net/lib_inetntoa.c index 64343dacc19..274728fe403 100644 --- a/libs/libc/net/lib_inetntoa.c +++ b/libs/libc/net/lib_inetntoa.c @@ -49,6 +49,7 @@ FAR char *inet_ntoa_r(struct in_addr in, FAR char *buf, size_t bufflen) { FAR unsigned char *ptr = (FAR unsigned char *)&in.s_addr; + snprintf(buf, bufflen, "%u.%u.%u.%u", ptr[0], ptr[1], ptr[2], ptr[3]); return buf; @@ -68,6 +69,7 @@ FAR char *inet_ntoa_r(struct in_addr in, FAR char *buf, size_t bufflen) FAR char *inet_ntoa(struct in_addr in) { static char buffer[INET_ADDRSTRLEN]; + return inet_ntoa_r(in, buffer, sizeof(buffer)); } diff --git a/libs/libc/net/lib_inetntop.c b/libs/libc/net/lib_inetntop.c index dbaf10e3b51..fd2193b17cb 100644 --- a/libs/libc/net/lib_inetntop.c +++ b/libs/libc/net/lib_inetntop.c @@ -294,20 +294,20 @@ FAR const char *inet_ntop(int af, FAR const void *src, FAR char *dest, switch (af) { #if defined(CONFIG_NET_IPv4) || defined(CONFIG_LIBC_IPv4_ADDRCONV) - case AF_INET: - ret = inet_ipv4_ntop(src, dest, size); - break; + case AF_INET: + ret = inet_ipv4_ntop(src, dest, size); + break; #endif #if defined(CONFIG_NET_IPv6) || defined(CONFIG_LIBC_IPv6_ADDRCONV) - case AF_INET6: - ret = inet_ipv6_ntop(src, dest, size); - break; + case AF_INET6: + ret = inet_ipv6_ntop(src, dest, size); + break; #endif - default: - ret = -EAFNOSUPPORT; - break; + default: + ret = -EAFNOSUPPORT; + break; } /* Handle errors in the conversion */ diff --git a/libs/libc/net/lib_nametoindex.c b/libs/libc/net/lib_nametoindex.c index 1e8c695f710..3745cfe05ef 100644 --- a/libs/libc/net/lib_nametoindex.c +++ b/libs/libc/net/lib_nametoindex.c @@ -55,9 +55,11 @@ unsigned int if_nametoindex(FAR const char *ifname) { int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL); + if (sockfd >= 0) { struct ifreq req; + strlcpy(req.ifr_name, ifname, IF_NAMESIZE); if (ioctl(sockfd, SIOCGIFINDEX, (unsigned long)&req) >= 0) { diff --git a/libs/libc/netdb/lib_dnscache.c b/libs/libc/netdb/lib_dnscache.c index d613ce4750c..00602d62f61 100644 --- a/libs/libc/netdb/lib_dnscache.c +++ b/libs/libc/netdb/lib_dnscache.c @@ -129,6 +129,7 @@ void dns_save_answer(FAR const char *hostname, if (next == g_dns_tail) { int tmp = g_dns_tail + 1; + if (tmp >= CONFIG_NETDB_DNSCLIENT_ENTRIES) { tmp = 0; diff --git a/libs/libc/netdb/lib_dnsnotify.c b/libs/libc/netdb/lib_dnsnotify.c index d8b6eb280e4..ed5403781bf 100644 --- a/libs/libc/netdb/lib_dnsnotify.c +++ b/libs/libc/netdb/lib_dnsnotify.c @@ -129,6 +129,7 @@ void dns_notify_nameserver(FAR const struct sockaddr *addr, for (entry = dq_peek(&g_dns_notify); entry; entry = dq_next(entry)) { FAR struct dns_notify_s *notify = (FAR struct dns_notify_s *)entry; + notify->callback(notify->arg, (FAR struct sockaddr *)addr, addrlen); } diff --git a/libs/libc/netdb/lib_dnsquery.c b/libs/libc/netdb/lib_dnsquery.c index adf14ba8f02..db4a7ef022f 100644 --- a/libs/libc/netdb/lib_dnsquery.c +++ b/libs/libc/netdb/lib_dnsquery.c @@ -131,6 +131,7 @@ static ssize_t stream_send(int fd, FAR const void *buf, size_t len) while (len > 0) { ssize_t ret = send(fd, buf, len, 0); + if (ret == -1) { if (total == 0) @@ -169,6 +170,7 @@ static ssize_t stream_recv(int fd, FAR void *buf, size_t len) while (len > 0) { ssize_t ret = recv(fd, buf, len, 0); + if (ret == 0) { /* the peer closed the connection */ diff --git a/libs/libc/netdb/lib_getaddrinfo.c b/libs/libc/netdb/lib_getaddrinfo.c index 9b68bdcc4f3..fe1cb844a48 100644 --- a/libs/libc/netdb/lib_getaddrinfo.c +++ b/libs/libc/netdb/lib_getaddrinfo.c @@ -217,6 +217,7 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname, if (family == AF_INET || family == AF_UNSPEC) { struct in_addr addr; + memset(&addr, 0, sizeof(struct in_addr)); ai = alloc_ai(AF_INET, socktype, proto, port, &addr); if (ai != NULL) @@ -230,6 +231,7 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname, if (family == AF_INET6 || family == AF_UNSPEC) { struct in6_addr addr; + memset(&addr, 0, sizeof(struct in6_addr)); ai = alloc_ai(AF_INET6, socktype, proto, port, &addr); if (ai != NULL) diff --git a/libs/libc/netdb/lib_gethostbyaddrr.c b/libs/libc/netdb/lib_gethostbyaddrr.c index 117fb219217..ce39670a4db 100644 --- a/libs/libc/netdb/lib_gethostbyaddrr.c +++ b/libs/libc/netdb/lib_gethostbyaddrr.c @@ -300,6 +300,7 @@ int lib_hostfile_lookup(FAR const void *addr, socklen_t len, int type, */ FAR char *hostaddr = host->h_addr_list[0]; + if (hostaddr != NULL) { ninfo("Comparing addresses...\n"); diff --git a/libs/libc/netdb/lib_proto.c b/libs/libc/netdb/lib_proto.c index 3e71eb584bd..50abac1f1f4 100644 --- a/libs/libc/netdb/lib_proto.c +++ b/libs/libc/netdb/lib_proto.c @@ -53,6 +53,7 @@ FAR struct protoent *getprotoent(void) { FAR struct protoent *result; int ret = getprotoent_r(&result_buf, NULL, 0, &result); + return ret == OK ? &result_buf : NULL; } @@ -60,6 +61,7 @@ FAR struct protoent *getprotobyname(FAR const char *name) { FAR struct protoent *result; int ret = getprotobyname_r(name, &result_buf, NULL, 0, &result); + return ret == OK ? &result_buf : NULL; } @@ -67,5 +69,6 @@ FAR struct protoent *getprotobynumber(int proto) { FAR struct protoent *result; int ret = getprotobynumber_r(proto, &result_buf, NULL, 0, &result); + return ret == OK ? &result_buf : NULL; } diff --git a/libs/libc/netdb/lib_protor.c b/libs/libc/netdb/lib_protor.c index 21a64149fdb..66ec0d6290a 100644 --- a/libs/libc/netdb/lib_protor.c +++ b/libs/libc/netdb/lib_protor.c @@ -99,6 +99,7 @@ int getprotoent_r(FAR struct protoent *result_buf, FAR char *buf, size_t buflen, FAR struct protoent **result) { int idx = result_buf->idx; + if (idx >= sizeof(g_protos)) { *result = NULL; @@ -120,6 +121,7 @@ int getprotobyname_r(FAR const char *name, size_t buflen, FAR struct protoent **result) { int ret; + endprotoent_r(result_buf); do { @@ -135,6 +137,7 @@ int getprotobynumber_r(int proto, size_t buflen, FAR struct protoent **result) { int ret; + endprotoent_r(result_buf); do { diff --git a/libs/libc/obstack/lib_obstack_copy.c b/libs/libc/obstack/lib_obstack_copy.c index 0f3207bd93f..210b94c17f1 100644 --- a/libs/libc/obstack/lib_obstack_copy.c +++ b/libs/libc/obstack/lib_obstack_copy.c @@ -50,6 +50,7 @@ FAR void *obstack_copy(FAR struct obstack *h, FAR const void *address, size_t size) { FAR void *res = obstack_alloc(h, size); + memcpy(res, address, size); return res; } @@ -74,6 +75,7 @@ FAR void *obstack_copy0(FAR struct obstack *h, FAR const void *address, size_t size) { FAR char *res = obstack_alloc(h, size + 1); + memcpy(res, address, size); res[size] = '\0'; return res; diff --git a/libs/libc/obstack/lib_obstack_finish.c b/libs/libc/obstack/lib_obstack_finish.c index 7480f486db7..87ff1910a63 100644 --- a/libs/libc/obstack/lib_obstack_finish.c +++ b/libs/libc/obstack/lib_obstack_finish.c @@ -95,6 +95,7 @@ FAR void *obstack_finish(FAR struct obstack *h) FAR void *obstack_finish_norealloc(FAR struct obstack *h) { FAR char *res = h->object_base; + h->object_base = h->next_free; return res; } diff --git a/libs/libc/obstack/lib_obstack_make_room.c b/libs/libc/obstack/lib_obstack_make_room.c index 2f7fcba3d7d..8266a4d2cc5 100644 --- a/libs/libc/obstack/lib_obstack_make_room.c +++ b/libs/libc/obstack/lib_obstack_make_room.c @@ -93,6 +93,7 @@ void obstack_make_room(FAR struct obstack *h, size_t size) */ FAR struct _obstack_chunk *prev = h->chunk; + h->chunk = lib_obstack_malloc(size); h->chunk->prev = prev; diff --git a/libs/libc/pthread/pthread_barrierwait.c b/libs/libc/pthread/pthread_barrierwait.c index 9d8ea6c11a7..eb8cb4c59d1 100644 --- a/libs/libc/pthread/pthread_barrierwait.c +++ b/libs/libc/pthread/pthread_barrierwait.c @@ -117,6 +117,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier) /* If the thread is awakened by a signal, just continue to wait */ int errornumber = get_errno(); + if (errornumber != EINTR) { return errornumber; diff --git a/libs/libc/pthread/pthread_kill.c b/libs/libc/pthread/pthread_kill.c index bcd509a8185..a9a9d14a905 100644 --- a/libs/libc/pthread/pthread_kill.c +++ b/libs/libc/pthread/pthread_kill.c @@ -62,6 +62,7 @@ int pthread_kill(pthread_t thread, int signo) { int ret = tkill((pid_t)thread, signo); + if (ret < 0) { ret = get_errno(); diff --git a/libs/libc/pwd/lib_find_pwdfile.c b/libs/libc/pwd/lib_find_pwdfile.c index bd520c998b7..d593f198f6c 100644 --- a/libs/libc/pwd/lib_find_pwdfile.c +++ b/libs/libc/pwd/lib_find_pwdfile.c @@ -70,6 +70,7 @@ static int pwd_match_name(FAR const struct passwd *entry, UNUSED(index); FAR const char *uname = (FAR const char *)arg; + return strcmp(entry->pw_name, uname) == 0 ? 1 : 0; } @@ -98,6 +99,7 @@ static int pwd_match_uid(FAR const struct passwd *entry, UNUSED(index); int match_uid = (int)arg; + return match_uid == entry->pw_uid ? 1 : 0; } @@ -161,6 +163,7 @@ static int pwd_foreach(pwd_foreach_match_t match, uintptr_t arg, if (stream == NULL) { int errcode = get_errno(); + DEBUGASSERT(errcode > 0); return -errcode; } diff --git a/libs/libc/pwd/lib_getpwbuf.c b/libs/libc/pwd/lib_getpwbuf.c index c05659c6415..4857c06814e 100644 --- a/libs/libc/pwd/lib_getpwbuf.c +++ b/libs/libc/pwd/lib_getpwbuf.c @@ -62,5 +62,6 @@ FAR struct passwd *getpwbuf(uid_t uid, gid_t gid, FAR const char *name, FAR struct passwd *pwd = NULL; int ret = getpwbuf_r(uid, gid, name, gecos, dir, shell, passwd, &g_passwd, g_passwd_buffer, sizeof(g_passwd_buffer), &pwd); + return ret == 0 ? pwd : NULL; } diff --git a/libs/libc/pwd/lib_getpwent.c b/libs/libc/pwd/lib_getpwent.c index 0e9ba86d7ca..086b9c0c527 100644 --- a/libs/libc/pwd/lib_getpwent.c +++ b/libs/libc/pwd/lib_getpwent.c @@ -99,6 +99,7 @@ void endpwent(void) FAR struct passwd *getpwent(void) { FAR struct passwd *pwd; + getpwent_r(&g_passwd, g_passwd_buffer, CONFIG_LIBC_PASSWD_LINESIZE, &pwd); return pwd; diff --git a/libs/libc/pwd/lib_getspnam.c b/libs/libc/pwd/lib_getspnam.c index 127f2d7ed97..a34783710b9 100644 --- a/libs/libc/pwd/lib_getspnam.c +++ b/libs/libc/pwd/lib_getspnam.c @@ -46,6 +46,7 @@ FAR struct spwd *getspnam(FAR const char *name) { size_t nsize = sizeof(ROOT_NAME); size_t psize = sizeof(ROOT_PWDP); + result = &g_spwd; result->sp_namp = g_passwd_buffer; diff --git a/libs/libc/sched/task_gettid.c b/libs/libc/sched/task_gettid.c index 33abbcc2e3b..566a2281091 100644 --- a/libs/libc/sched/task_gettid.c +++ b/libs/libc/sched/task_gettid.c @@ -52,5 +52,6 @@ pid_t gettid(void) { FAR struct tls_info_s *tls = tls_get_info(); + return tls->tl_tid; } diff --git a/libs/libc/search/hash_func.c b/libs/libc/search/hash_func.c index ed4df891a4b..8383ac47a03 100644 --- a/libs/libc/search/hash_func.c +++ b/libs/libc/search/hash_func.c @@ -2,7 +2,8 @@ * libs/libc/search/hash_func.c * * SPDX-License-Identifier: BSD-3-Clause-UC - * SPDX-FileCopyrightText: 1990, 1993 The Regents of the University of California. + * SPDX-FileCopyrightText: 1990, 1993 The Regents of the University of + * California. * * This code is derived from software contributed to Berkeley by * Margo Seltzer. diff --git a/libs/libc/spawn/lib_psfa_dump.c b/libs/libc/spawn/lib_psfa_dump.c index bf70d0821f2..6c5532ce44e 100644 --- a/libs/libc/spawn/lib_psfa_dump.c +++ b/libs/libc/spawn/lib_psfa_dump.c @@ -83,38 +83,38 @@ void posix_spawn_file_actions_dump( { switch (entry->action) { - case SPAWN_FILE_ACTION_CLOSE: - { - FAR struct spawn_close_file_action_s *action = - (FAR struct spawn_close_file_action_s *)entry; - - _err(" CLOSE: fd=%d\n", action->fd); - } - break; - - case SPAWN_FILE_ACTION_DUP2: - { - FAR struct spawn_dup2_file_action_s *action = - (FAR struct spawn_dup2_file_action_s *)entry; - - _err(" DUP2: %d->%d\n", action->fd1, action->fd2); - } - break; - - case SPAWN_FILE_ACTION_OPEN: - { - FAR struct spawn_open_file_action_s *action = - (FAR struct spawn_open_file_action_s *)entry; - - _err(" OPEN: path=%s oflags=%04x mode=%04x fd=%d\n", - action->path, action->oflags, action->mode, action->fd); - } - break; - - case SPAWN_FILE_ACTION_NONE: - default: - _err(" ERROR: Unknown action: %d\n", entry->action); - break; + case SPAWN_FILE_ACTION_CLOSE: + { + FAR struct spawn_close_file_action_s *action = + (FAR struct spawn_close_file_action_s *)entry; + + _err(" CLOSE: fd=%d\n", action->fd); + } + break; + + case SPAWN_FILE_ACTION_DUP2: + { + FAR struct spawn_dup2_file_action_s *action = + (FAR struct spawn_dup2_file_action_s *)entry; + + _err(" DUP2: %d->%d\n", action->fd1, action->fd2); + } + break; + + case SPAWN_FILE_ACTION_OPEN: + { + FAR struct spawn_open_file_action_s *action = + (FAR struct spawn_open_file_action_s *)entry; + + _err(" OPEN: path=%s oflags=%04x mode=%04x fd=%d\n", + action->path, action->oflags, action->mode, action->fd); + } + break; + + case SPAWN_FILE_ACTION_NONE: + default: + _err(" ERROR: Unknown action: %d\n", entry->action); + break; } } } diff --git a/libs/libc/stdio/lib_fmemopen.c b/libs/libc/stdio/lib_fmemopen.c index 4d9645952da..9829c79396e 100644 --- a/libs/libc/stdio/lib_fmemopen.c +++ b/libs/libc/stdio/lib_fmemopen.c @@ -61,6 +61,7 @@ static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size) { FAR struct fmemopen_cookie_s *fmemopen_cookie = (FAR struct fmemopen_cookie_s *)c; + if (fmemopen_cookie->pos + size > fmemopen_cookie->end) { size = fmemopen_cookie->end - fmemopen_cookie->pos; @@ -80,6 +81,7 @@ static ssize_t fmemopen_write(FAR void *c, FAR const char *buf, size_t size) { FAR struct fmemopen_cookie_s *fmemopen_cookie = (FAR struct fmemopen_cookie_s *)c; + if (size + fmemopen_cookie->pos > fmemopen_cookie->size) { size = fmemopen_cookie->size - fmemopen_cookie->pos; @@ -153,6 +155,7 @@ static int fmemopen_close(FAR void *c) { FAR struct fmemopen_cookie_s *fmemopen_cookie = (FAR struct fmemopen_cookie_s *)c; + if (fmemopen_cookie->custom) { lib_free(fmemopen_cookie->buf); diff --git a/libs/libc/stdio/lib_fopen.c b/libs/libc/stdio/lib_fopen.c index d763904ac90..cc72a095731 100644 --- a/libs/libc/stdio/lib_fopen.c +++ b/libs/libc/stdio/lib_fopen.c @@ -284,8 +284,8 @@ int lib_mode2oflags(FAR const char *mode) /* Open for read/write access */ oflags |= O_RDWR; - } - break; + } + break; case MODE_W: { diff --git a/libs/libc/stdio/lib_fputwc.c b/libs/libc/stdio/lib_fputwc.c index c114c19d2e8..7b31bc41834 100644 --- a/libs/libc/stdio/lib_fputwc.c +++ b/libs/libc/stdio/lib_fputwc.c @@ -104,6 +104,7 @@ wint_t fputwc(wchar_t c, FAR FILE *f) { flockfile(f); wint_t wc = fputwc_unlocked(c, f); + funlockfile(f); return wc; } diff --git a/libs/libc/stdio/lib_fputws.c b/libs/libc/stdio/lib_fputws.c index 304426c3e87..f15c1d927a9 100644 --- a/libs/libc/stdio/lib_fputws.c +++ b/libs/libc/stdio/lib_fputws.c @@ -93,6 +93,7 @@ int fputws_unlocked(FAR const wchar_t *ws, FAR FILE *f) int fputws(FAR const wchar_t *ws, FAR FILE *f) { int l; + flockfile(f); l = fputws_unlocked(ws, f); funlockfile(f); diff --git a/libs/libc/stdio/lib_ftello.c b/libs/libc/stdio/lib_ftello.c index 0d4c9341f99..33d5f84fde1 100644 --- a/libs/libc/stdio/lib_ftello.c +++ b/libs/libc/stdio/lib_ftello.c @@ -55,6 +55,7 @@ static off_t lib_getoffset(FAR FILE *stream) { off_t offset = 0; + flockfile(stream); if (stream->fs_bufstart != diff --git a/libs/libc/stdio/lib_getchar.c b/libs/libc/stdio/lib_getchar.c index 4034661d8a6..99ed7a9ed19 100644 --- a/libs/libc/stdio/lib_getchar.c +++ b/libs/libc/stdio/lib_getchar.c @@ -37,6 +37,7 @@ int getchar(void) return fgetc(stdin); #else unsigned char c; + return read(STDIN_FILENO, &c, 1) == 1 ? c : EOF; #endif } @@ -47,6 +48,7 @@ int getchar_unlocked(void) return fgetc_unlocked(stdin); #else unsigned char c; + return read(STDIN_FILENO, &c, 1) == 1 ? c : EOF; #endif } diff --git a/libs/libc/stdio/lib_libdgets.c b/libs/libc/stdio/lib_libdgets.c index 0f1f8da350a..a37b07b1f74 100644 --- a/libs/libc/stdio/lib_libdgets.c +++ b/libs/libc/stdio/lib_libdgets.c @@ -43,6 +43,7 @@ static int dgetc(int fd) { unsigned char c; + return read(fd, &c, 1) == 1 ? c : EOF; } diff --git a/libs/libc/stdio/lib_putchar.c b/libs/libc/stdio/lib_putchar.c index e993667e2c0..b8fe65df60e 100644 --- a/libs/libc/stdio/lib_putchar.c +++ b/libs/libc/stdio/lib_putchar.c @@ -37,6 +37,7 @@ int putchar(int c) return fputc(c, stdout); #else unsigned char tmp = c; + return write(STDOUT_FILENO, &tmp, 1) == 1 ? c : EOF; #endif } @@ -47,6 +48,7 @@ int putchar_unlocked(int c) return fputc_unlocked(c, stdout); #else unsigned char tmp = c; + return write(STDOUT_FILENO, &tmp, 1) == 1 ? c : EOF; #endif } diff --git a/libs/libc/stdio/lib_puts.c b/libs/libc/stdio/lib_puts.c index 8e57f888e7c..7b751e4f912 100644 --- a/libs/libc/stdio/lib_puts.c +++ b/libs/libc/stdio/lib_puts.c @@ -62,6 +62,7 @@ int puts(FAR const IPTR char *s) /* Followed by a newline */ char newline = '\n'; + ret = lib_fwrite_unlocked(&newline, 1, stream); if (ret > 0) { diff --git a/libs/libc/stdio/lib_putwc.c b/libs/libc/stdio/lib_putwc.c index 9fc4d162217..f972805d882 100644 --- a/libs/libc/stdio/lib_putwc.c +++ b/libs/libc/stdio/lib_putwc.c @@ -78,6 +78,7 @@ wint_t putwc_unlocked(wchar_t c, FAR FILE *f) wint_t putwc(wchar_t c, FAR FILE *f) { wint_t wc; + flockfile(f); wc = putwc_unlocked(c, f); funlockfile(f); diff --git a/libs/libc/stdio/lib_setvbuf.c b/libs/libc/stdio/lib_setvbuf.c index 3426b6deeb1..8ec09331558 100644 --- a/libs/libc/stdio/lib_setvbuf.c +++ b/libs/libc/stdio/lib_setvbuf.c @@ -219,9 +219,9 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) DEBUGPANIC(); } - /* Do not release the previous buffer if it was allocated by the user - * on a previous call to setvbuf(). - */ + /* Do not release the previous buffer if it was allocated by the user + * on a previous call to setvbuf(). + */ if (stream->fs_bufstart != NULL && (stream->fs_flags & __FS_FLAG_UBF) == 0) diff --git a/libs/libc/stdlib/lib_arc4random.c b/libs/libc/stdlib/lib_arc4random.c index e8760d17335..6c434f8ce7e 100644 --- a/libs/libc/stdlib/lib_arc4random.c +++ b/libs/libc/stdlib/lib_arc4random.c @@ -46,6 +46,7 @@ static int getrandom_all(FAR void *buf, size_t size, int flags) while (size > 0) { ssize_t ret = getrandom(tmp, size, flags); + if (ret < 0) { if (get_errno() == EINTR) diff --git a/libs/libc/stdlib/lib_ptsname.c b/libs/libc/stdlib/lib_ptsname.c index ddf92bcbe19..6cba1e57ba6 100644 --- a/libs/libc/stdlib/lib_ptsname.c +++ b/libs/libc/stdlib/lib_ptsname.c @@ -54,6 +54,7 @@ FAR char *ptsname(int fd) { static char devname[16]; int ret = ptsname_r(fd, devname, 16); + return ret < 0 ? NULL : devname; } diff --git a/libs/libc/stdlib/lib_strtold.c b/libs/libc/stdlib/lib_strtold.c index e03ba22e72a..d6c2024afe8 100644 --- a/libs/libc/stdlib/lib_strtold.c +++ b/libs/libc/stdlib/lib_strtold.c @@ -674,14 +674,14 @@ static long_double strtox(FAR const char *str, FAR char **endptr, int flag) switch (*s) { - case '-': - negative = 1; /* Fall through to increment position */ + case '-': + negative = 1; /* Fall through to increment position */ - case '+': - s++; + case '+': + s++; - default: - break; + default: + break; } for (i = 0; i < 8 && (*s | 32) == "infinity"[i]; i++) diff --git a/libs/libc/stream/lib_blkoutstream.c b/libs/libc/stream/lib_blkoutstream.c index 793a0fe1d8f..73db682cc15 100644 --- a/libs/libc/stream/lib_blkoutstream.c +++ b/libs/libc/stream/lib_blkoutstream.c @@ -213,6 +213,7 @@ static ssize_t blkoutstream_puts(FAR struct lib_sostream_s *self, static void blkoutstream_putc(FAR struct lib_sostream_s *self, int ch) { char tmp = ch; + blkoutstream_puts(self, &tmp, 1); } diff --git a/libs/libc/stream/lib_fileinstream.c b/libs/libc/stream/lib_fileinstream.c index dd9e23a8ee8..11d10abd402 100644 --- a/libs/libc/stream/lib_fileinstream.c +++ b/libs/libc/stream/lib_fileinstream.c @@ -68,6 +68,7 @@ static ssize_t fileinstream_gets(FAR struct lib_instream_s *self, static int fileinstream_getc(FAR struct lib_instream_s *self) { unsigned char ch; + return fileinstream_gets(self, &ch, 1) == 1 ? ch : EOF; } diff --git a/libs/libc/stream/lib_fileoutstream.c b/libs/libc/stream/lib_fileoutstream.c index 785e1d39237..47dda977b07 100644 --- a/libs/libc/stream/lib_fileoutstream.c +++ b/libs/libc/stream/lib_fileoutstream.c @@ -77,6 +77,7 @@ static ssize_t fileoutstream_puts(FAR struct lib_outstream_s *self, static void fileoutstream_putc(FAR struct lib_outstream_s *self, int ch) { char tmp = ch; + fileoutstream_puts(self, &tmp, 1); } diff --git a/libs/libc/stream/lib_lowoutstream.c b/libs/libc/stream/lib_lowoutstream.c index 5a7b64b73c4..f94c26ba98d 100644 --- a/libs/libc/stream/lib_lowoutstream.c +++ b/libs/libc/stream/lib_lowoutstream.c @@ -84,6 +84,7 @@ static ssize_t lowoutstream_puts(FAR struct lib_outstream_s *self, { FAR const char *str = (FAR const char *)buf; size_t idx = 0; + DEBUGASSERT(self); while (idx < len && str[idx] != 0) diff --git a/libs/libc/stream/lib_memoutstream.c b/libs/libc/stream/lib_memoutstream.c index 2db0f6bd087..59299324444 100644 --- a/libs/libc/stream/lib_memoutstream.c +++ b/libs/libc/stream/lib_memoutstream.c @@ -69,6 +69,7 @@ static ssize_t memoutstream_puts(FAR struct lib_outstream_s *self, static void memoutstream_putc(FAR struct lib_outstream_s *self, int ch) { char tmp = ch; + memoutstream_puts(self, &tmp, 1); } diff --git a/libs/libc/stream/lib_mtdoutstream.c b/libs/libc/stream/lib_mtdoutstream.c index c9a42a687c1..68c76fef559 100644 --- a/libs/libc/stream/lib_mtdoutstream.c +++ b/libs/libc/stream/lib_mtdoutstream.c @@ -241,6 +241,7 @@ static ssize_t mtdoutstream_puts(FAR struct lib_outstream_s *self, static void mtdoutstream_putc(FAR struct lib_outstream_s *self, int ch) { char tmp = ch; + mtdoutstream_puts(self, &tmp, 1); } diff --git a/libs/libc/stream/lib_mtdsostream.c b/libs/libc/stream/lib_mtdsostream.c index 52e2221aa84..9f0e586ce1e 100644 --- a/libs/libc/stream/lib_mtdsostream.c +++ b/libs/libc/stream/lib_mtdsostream.c @@ -172,6 +172,7 @@ static ssize_t mtdsostream_puts(FAR struct lib_sostream_s *self, static void mtdsostream_putc(FAR struct lib_sostream_s *self, int ch) { char tmp = ch; + mtdsostream_puts(self, &tmp, 1); } diff --git a/libs/libc/stream/lib_rawoutstream.c b/libs/libc/stream/lib_rawoutstream.c index 98b7cf895d4..dcb91b375f7 100644 --- a/libs/libc/stream/lib_rawoutstream.c +++ b/libs/libc/stream/lib_rawoutstream.c @@ -78,6 +78,7 @@ static ssize_t rawoutstream_puts(FAR struct lib_outstream_s *self, static void rawoutstream_putc(FAR struct lib_outstream_s *self, int ch) { char tmp = ch; + rawoutstream_puts(self, &tmp, 1); } diff --git a/libs/libc/stream/lib_syslograwstream.c b/libs/libc/stream/lib_syslograwstream.c index 270205f83a4..bc01dcbed4f 100644 --- a/libs/libc/stream/lib_syslograwstream.c +++ b/libs/libc/stream/lib_syslograwstream.c @@ -124,6 +124,7 @@ static void syslograwstream_addchar(FAR struct lib_syslograwstream_s *stream, /* Yes.. then flush the buffer */ int ret = syslograwstream_flush(&stream->common); + if (ret < 0) { stream->offset = 0; @@ -141,9 +142,11 @@ syslograwstream_addstring(FAR struct lib_syslograwstream_s *stream, FAR const char *buff, size_t len) { ssize_t ret = 0; + do { size_t remain = CONFIG_SYSLOG_BUFSIZE - stream->offset; + remain = remain > len - ret ? len - ret : remain; memcpy(stream->buffer + stream->offset, buff + ret, remain); stream->offset += remain; @@ -160,11 +163,12 @@ syslograwstream_addstring(FAR struct lib_syslograwstream_s *stream, /* Yes.. then flush the buffer */ int ret_flush = syslograwstream_flush(&stream->common); + if (ret_flush < 0) { - stream->offset = 0; - stream->common.nput = 0; - break; + stream->offset = 0; + stream->common.nput = 0; + break; } } } diff --git a/libs/libc/string/lib_bsdmemccpy.c b/libs/libc/string/lib_bsdmemccpy.c index 59eee4246ca..b35d698e04a 100644 --- a/libs/libc/string/lib_bsdmemccpy.c +++ b/libs/libc/string/lib_bsdmemccpy.c @@ -100,6 +100,7 @@ FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n) while (n >= LITTLEBLOCKSIZE) { libc_data_t buffer = (libc_data_t)(*paligned_in); + buffer ^= mask; if (DETECTNULL(buffer)) { @@ -128,6 +129,7 @@ FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n) while (n >= LITTLEBLOCKSIZE4) { uint32_t buffer = *paligned_in; + buffer ^= mask; if (DETECTNULL32(buffer)) { diff --git a/libs/libc/string/lib_bsdstrcat.c b/libs/libc/string/lib_bsdstrcat.c index 898ef95876e..0fecd63dc83 100644 --- a/libs/libc/string/lib_bsdstrcat.c +++ b/libs/libc/string/lib_bsdstrcat.c @@ -50,6 +50,7 @@ FAR char *strcat(FAR char *dest, FAR const char *src) if (ALIGNED(dest)) { FAR libc_data_t *aligned_s1 = (FAR libc_data_t *)dest; + while (!DETECTNULL(*aligned_s1)) { aligned_s1++; diff --git a/libs/libc/string/lib_memcpy.c b/libs/libc/string/lib_memcpy.c index 606aaaa753d..289e7ffbc09 100644 --- a/libs/libc/string/lib_memcpy.c +++ b/libs/libc/string/lib_memcpy.c @@ -45,6 +45,7 @@ FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n) { FAR unsigned char *pout = (FAR unsigned char *)dest; FAR unsigned char *pin = (FAR unsigned char *)src; + while (n-- > 0) { *pout++ = *pin++; diff --git a/libs/libc/string/lib_memmem.c b/libs/libc/string/lib_memmem.c index e9ad2cdb496..b22883e18a0 100644 --- a/libs/libc/string/lib_memmem.c +++ b/libs/libc/string/lib_memmem.c @@ -74,22 +74,22 @@ FAR void *memmem(FAR const void *haystack, size_t haystacklen, { case (0): - /* empty needle */ + /* empty needle */ - return (FAR void *)haystack; - break; + return (FAR void *)haystack; + break; case (1): - /* special case for single-character needles */ + /* special case for single-character needles */ - return memchr(haystack, - *((FAR unsigned char *)needle), haystacklen); - break; + return memchr(haystack, + *((FAR unsigned char *)needle), haystacklen); + break; } /* start searching through haystack only from the first occurrence of - * the first character of needle. - */ + * the first character of needle. + */ haystack_ptr = (FAR const unsigned char *)memchr(haystack, *((FAR const unsigned char *)needle), haystacklen); @@ -133,18 +133,18 @@ FAR void *memmem(FAR const void *haystack, size_t haystacklen, } /* we will call memcmp() only once we know that the sums are equal - * and that LONG_INT_N_BYTES last chars are equal, so it will be - * enough to compare all but the last LONG_INT_N_BYTES + 1 - * characters. - */ + * and that LONG_INT_N_BYTES last chars are equal, so it will be + * enough to compare all but the last LONG_INT_N_BYTES + 1 + * characters. + */ compare_len = needlelen - (LONG_INT_N_BYTES + 1); /* At this point: - * needle is at least two characters long - * haystack is at least needlelen characters long (also at least two) - * the first characters of needle and haystack are identical - */ + * needle is at least two characters long + * haystack is at least needlelen characters long (also at least two) + * the first characters of needle and haystack are identical + */ if (sums_diff == 0 && last_haystack_chars == last_needle_chars @@ -154,9 +154,9 @@ FAR void *memmem(FAR const void *haystack, size_t haystacklen, } /* iterate through the remainder of haystack, updating the sums' - * differenceand checking for identity whenever the difference - * is zero. - */ + * differenceand checking for identity whenever the difference + * is zero. + */ for (i = haystacklen - needlelen; i > 0; --i) { @@ -165,8 +165,8 @@ FAR void *memmem(FAR const void *haystack, size_t haystacklen, sums_diff -= *(FAR const unsigned char *)haystack++; sums_diff += *haystack_ptr++; /* if sums_diff == 0, we know that the sums are equal, so it is - * enough to compare all but the last characters. - */ + * enough to compare all but the last characters. + */ if (sums_diff == 0 && last_haystack_chars == last_needle_chars @@ -187,16 +187,16 @@ FAR void *memmem(FAR const void *haystack, size_t haystacklen, } /* we will call memcmp() only once we know that the sums are equal, - * so it will be enough to compare all but the last characters. - */ + * so it will be enough to compare all but the last characters. + */ compare_len = needlelen - 1; /* At this point: - * needle is at least two characters long - * haystack is at least needlelen characters long (also at least two) - * the first characters of needle and haystack are identical - */ + * needle is at least two characters long + * haystack is at least needlelen characters long (also at least two) + * the first characters of needle and haystack are identical + */ if (sums_diff == 0 && memcmp(haystack, needle, compare_len) == 0) @@ -205,17 +205,17 @@ FAR void *memmem(FAR const void *haystack, size_t haystacklen, } /* iterate through the remainder of haystack, updating the sums' - * difference and checking for identity whenever the difference - * is zero. - */ + * difference and checking for identity whenever the difference + * is zero. + */ for (i = haystacklen - needlelen; i > 0; --i) { sums_diff -= *(FAR const unsigned char *)haystack++; sums_diff += *haystack_ptr++; /* if sums_diff == 0, we know that the sums are equal, so it is - * enough to compare all but the last characters. - */ + * enough to compare all but the last characters. + */ if (sums_diff == 0 && memcmp(haystack, needle, compare_len) == 0) @@ -243,8 +243,8 @@ FAR void *memmem(FAR const void *haystack, size_t haystacklen, } /* iterate through the remainder of haystack, updating the last char - * data and checking for equality. - */ + * data and checking for equality. + */ for (i = haystacklen - needlelen; i > 0; --i) { @@ -279,8 +279,8 @@ FAR void *memmem(FAR const void *haystack, size_t haystacklen, } /* iterate through the remainder of haystack, updating the last char - * data and checking for equality. - */ + * data and checking for equality. + */ for (i = haystacklen - needlelen; i > 0; --i) { diff --git a/libs/libc/string/lib_strcasecmp.c b/libs/libc/string/lib_strcasecmp.c index 9efe36b54ab..97f6cd79121 100644 --- a/libs/libc/string/lib_strcasecmp.c +++ b/libs/libc/string/lib_strcasecmp.c @@ -40,6 +40,7 @@ int strcasecmp(FAR const char *cs, FAR const char *ct) { register int result; + for (; ; ) { if ((result = toupper(*cs) - toupper(*ct)) != 0 || diff --git a/libs/libc/string/lib_strcmp.c b/libs/libc/string/lib_strcmp.c index d921eaa5b0b..6895aba1254 100644 --- a/libs/libc/string/lib_strcmp.c +++ b/libs/libc/string/lib_strcmp.c @@ -39,6 +39,7 @@ int strcmp(FAR const char *cs, FAR const char *ct) { register int result; + for (; ; ) { if ((result = (unsigned char)*cs - (unsigned char)*ct++) != 0 || diff --git a/libs/libc/string/lib_strcpy.c b/libs/libc/string/lib_strcpy.c index 011ed3efbb7..b0bb3bda852 100644 --- a/libs/libc/string/lib_strcpy.c +++ b/libs/libc/string/lib_strcpy.c @@ -52,6 +52,7 @@ no_builtin("strcpy") FAR char *strcpy(FAR char *dest, FAR const char *src) { FAR char *tmp = dest; + while ((*dest++ = *src++) != '\0'); return tmp; } diff --git a/libs/libc/string/lib_strcspn.c b/libs/libc/string/lib_strcspn.c index 82bd46ef06d..13053d80757 100644 --- a/libs/libc/string/lib_strcspn.c +++ b/libs/libc/string/lib_strcspn.c @@ -46,6 +46,7 @@ no_builtin("strcspn") size_t strcspn(const char *s, const char *reject) { size_t i; + for (i = 0; s[i] && strchr(reject, s[i]) == NULL; i++); return i; } diff --git a/libs/libc/string/lib_strlen.c b/libs/libc/string/lib_strlen.c index b77d2300ddb..e986d6f9fb0 100644 --- a/libs/libc/string/lib_strlen.c +++ b/libs/libc/string/lib_strlen.c @@ -40,6 +40,7 @@ no_builtin("strlen") size_t strlen(FAR const char *s) { FAR const char *sc; + for (sc = s; *sc != '\0'; ++sc); return sc - s; } diff --git a/libs/libc/string/lib_strncasecmp.c b/libs/libc/string/lib_strncasecmp.c index 52d9339de45..189e37448ad 100644 --- a/libs/libc/string/lib_strncasecmp.c +++ b/libs/libc/string/lib_strncasecmp.c @@ -41,6 +41,7 @@ int strncasecmp(FAR const char *cs, FAR const char *ct, size_t nb) { register int result = 0; + for (; nb > 0; nb--) { if ((result = toupper(*cs) - toupper(*ct)) != 0 || diff --git a/libs/libc/string/lib_strncmp.c b/libs/libc/string/lib_strncmp.c index 00ab1e753fe..14d0bb3629f 100644 --- a/libs/libc/string/lib_strncmp.c +++ b/libs/libc/string/lib_strncmp.c @@ -40,6 +40,7 @@ no_builtin("strncmp") int strncmp(FAR const char *cs, FAR const char *ct, size_t nb) { register int result = 0; + for (; nb > 0; nb--) { if ((result = (unsigned char)*cs - (unsigned char)*ct++) != 0 || diff --git a/libs/libc/string/lib_strnlen.c b/libs/libc/string/lib_strnlen.c index 94922d24b42..9923af81bb7 100644 --- a/libs/libc/string/lib_strnlen.c +++ b/libs/libc/string/lib_strnlen.c @@ -39,6 +39,7 @@ size_t strnlen(FAR const char *s, size_t maxlen) { FAR const char *sc; + for (sc = s; maxlen != 0 && *sc != '\0'; maxlen--, ++sc); return sc - s; } diff --git a/libs/libc/string/lib_strsignal.c b/libs/libc/string/lib_strsignal.c index 048dc5b6c24..9f80a7f5df2 100644 --- a/libs/libc/string/lib_strsignal.c +++ b/libs/libc/string/lib_strsignal.c @@ -74,49 +74,49 @@ FAR char *strsignal(int signum) #ifdef CONFIG_LIBC_STRSIGNAL /* Standard signals */ - CASE_SIG_STR(SIGHUP, "Hangup"); - CASE_SIG_STR(SIGINT, "Interrupt"); - CASE_SIG_STR(SIGQUIT, "Quit"); - CASE_SIG_STR(SIGILL, "Illegal instruction"); - CASE_SIG_STR(SIGTRAP, "Trace/breakpoint trap"); - CASE_SIG_STR(SIGABRT, "Aborted"); - CASE_SIG_STR(SIGBUS, "Bus error"); - CASE_SIG_STR(SIGFPE, "Arithmetic exception"); - CASE_SIG_STR(SIGKILL, "Killed"); - CASE_SIG_STR(SIGUSR1, "User defined signal 1"); - CASE_SIG_STR(SIGSEGV, "Invalid memory reference"); - CASE_SIG_STR(SIGUSR2, "User defined signal 2"); - CASE_SIG_STR(SIGPIPE, "Broken pipe"); - CASE_SIG_STR(SIGALRM, "Alarm clock"); - CASE_SIG_STR(SIGTERM, "Terminated"); - CASE_SIG_STR(SIGCHLD, "Child status changed"); - CASE_SIG_STR(SIGCONT, "Continued"); - CASE_SIG_STR(SIGSTOP, "Stopped (signal)"); - CASE_SIG_STR(SIGTSTP, "Stopped"); - CASE_SIG_STR(SIGTTIN, "Stopped (tty input)"); - CASE_SIG_STR(SIGTTOU, "Stopped (tty output)"); - CASE_SIG_STR(SIGURG, "Urgent I/O condition"); - CASE_SIG_STR(SIGXCPU, "CPU time limit exceeded"); - CASE_SIG_STR(SIGXFSZ, "File size limit exceeded"); - CASE_SIG_STR(SIGVTALRM, "Virtual timer expired"); - CASE_SIG_STR(SIGPROF, "Profiling timer expired"); - CASE_SIG_STR(SIGWINCH, "Window resize signal"); - CASE_SIG_STR(SIGPOLL, "Pollable event occurred"); - CASE_SIG_STR(SIGSYS, "Bad system call"); + CASE_SIG_STR(SIGHUP, "Hangup"); + CASE_SIG_STR(SIGINT, "Interrupt"); + CASE_SIG_STR(SIGQUIT, "Quit"); + CASE_SIG_STR(SIGILL, "Illegal instruction"); + CASE_SIG_STR(SIGTRAP, "Trace/breakpoint trap"); + CASE_SIG_STR(SIGABRT, "Aborted"); + CASE_SIG_STR(SIGBUS, "Bus error"); + CASE_SIG_STR(SIGFPE, "Arithmetic exception"); + CASE_SIG_STR(SIGKILL, "Killed"); + CASE_SIG_STR(SIGUSR1, "User defined signal 1"); + CASE_SIG_STR(SIGSEGV, "Invalid memory reference"); + CASE_SIG_STR(SIGUSR2, "User defined signal 2"); + CASE_SIG_STR(SIGPIPE, "Broken pipe"); + CASE_SIG_STR(SIGALRM, "Alarm clock"); + CASE_SIG_STR(SIGTERM, "Terminated"); + CASE_SIG_STR(SIGCHLD, "Child status changed"); + CASE_SIG_STR(SIGCONT, "Continued"); + CASE_SIG_STR(SIGSTOP, "Stopped (signal)"); + CASE_SIG_STR(SIGTSTP, "Stopped"); + CASE_SIG_STR(SIGTTIN, "Stopped (tty input)"); + CASE_SIG_STR(SIGTTOU, "Stopped (tty output)"); + CASE_SIG_STR(SIGURG, "Urgent I/O condition"); + CASE_SIG_STR(SIGXCPU, "CPU time limit exceeded"); + CASE_SIG_STR(SIGXFSZ, "File size limit exceeded"); + CASE_SIG_STR(SIGVTALRM, "Virtual timer expired"); + CASE_SIG_STR(SIGPROF, "Profiling timer expired"); + CASE_SIG_STR(SIGWINCH, "Window resize signal"); + CASE_SIG_STR(SIGPOLL, "Pollable event occurred"); + CASE_SIG_STR(SIGSYS, "Bad system call"); #endif /* CONFIG_LIBC_STRSIGNAL */ - default: - if (signum >= SIGRTMIN && signum <= SIGRTMAX) - { - snprintf(sigstr, sizeof(sigstr), "Real-time Signal %d", - signum - SIGRTMIN); - } - else - { - snprintf(sigstr, sizeof(sigstr), "Signal %d", signum); - } - break; + default: + if (signum >= SIGRTMIN && signum <= SIGRTMAX) + { + snprintf(sigstr, sizeof(sigstr), "Real-time Signal %d", + signum - SIGRTMIN); + } + else + { + snprintf(sigstr, sizeof(sigstr), "Signal %d", signum); + } + break; } /* Return a string devoid is meaning */ diff --git a/libs/libc/string/lib_strspn.c b/libs/libc/string/lib_strspn.c index c51d53be376..ad9658cb6b3 100644 --- a/libs/libc/string/lib_strspn.c +++ b/libs/libc/string/lib_strspn.c @@ -45,6 +45,7 @@ size_t strspn(const char *s, const char *accept) { size_t i; + for (i = 0; s[i] && strchr(accept, s[i]) != NULL; i++); return i; } diff --git a/libs/libc/string/lib_strxfrm.c b/libs/libc/string/lib_strxfrm.c index 07e9e11a820..12136b562a2 100644 --- a/libs/libc/string/lib_strxfrm.c +++ b/libs/libc/string/lib_strxfrm.c @@ -57,6 +57,7 @@ size_t strxfrm(FAR char *s1, FAR const char *s2, size_t n) { size_t res; + res = 0; while (n-- > 0) { diff --git a/libs/libc/string/lib_vikmemcpy.c b/libs/libc/string/lib_vikmemcpy.c index fb6aa64e01b..923bb29fe3e 100644 --- a/libs/libc/string/lib_vikmemcpy.c +++ b/libs/libc/string/lib_vikmemcpy.c @@ -299,31 +299,31 @@ FAR void *memcpy(FAR void *dest, FAR const void *src, size_t count) switch ((((uintptr_t)src8) PRE_SWITCH_ADJUST) & (TYPE_WIDTH - 1)) { - case 0: - COPY_NO_SHIFT(); - break; - case 1: - COPY_SHIFT(1); - break; - case 2: - COPY_SHIFT(2); - break; - case 3: - COPY_SHIFT(3); - break; + case 0: + COPY_NO_SHIFT(); + break; + case 1: + COPY_SHIFT(1); + break; + case 2: + COPY_SHIFT(2); + break; + case 3: + COPY_SHIFT(3); + break; #if TYPE_WIDTH > 4 - case 4: - COPY_SHIFT(4); - break; - case 5: - COPY_SHIFT(5); - break; - case 6: - COPY_SHIFT(6); - break; - case 7: - COPY_SHIFT(7); - break; + case 4: + COPY_SHIFT(4); + break; + case 5: + COPY_SHIFT(5); + break; + case 6: + COPY_SHIFT(6); + break; + case 7: + COPY_SHIFT(7); + break; #endif } diff --git a/libs/libc/termios/lib_isatty.c b/libs/libc/termios/lib_isatty.c index 7f1b8b792c1..6aa98ca905c 100644 --- a/libs/libc/termios/lib_isatty.c +++ b/libs/libc/termios/lib_isatty.c @@ -54,5 +54,6 @@ int isatty(int fd) { struct termios ts; + return (tcgetattr(fd, &ts) >= 0); } diff --git a/libs/libc/time/lib_asctime.c b/libs/libc/time/lib_asctime.c index 9eb32e83c33..09dd0ed6d56 100644 --- a/libs/libc/time/lib_asctime.c +++ b/libs/libc/time/lib_asctime.c @@ -52,5 +52,6 @@ FAR char *asctime(FAR const struct tm *tp) { static char buf[26]; + return asctime_r(tp, buf); } diff --git a/libs/libc/time/lib_daysbeforemonth.c b/libs/libc/time/lib_daysbeforemonth.c index 6ed303444fe..299085c61e6 100644 --- a/libs/libc/time/lib_daysbeforemonth.c +++ b/libs/libc/time/lib_daysbeforemonth.c @@ -64,6 +64,7 @@ static const uint16_t g_daysbeforemonth[13] = int clock_daysbeforemonth(int month, bool leap_year) { int retval = g_daysbeforemonth[month]; + if (month >= 2 && leap_year) { retval++; diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c index 5dee4270475..8953e6571d8 100644 --- a/libs/libc/time/lib_localtime.c +++ b/libs/libc/time/lib_localtime.c @@ -756,12 +756,14 @@ static int tzload(FAR const char *name, for (i = 0; i < sp->timecnt; ++i) { int_fast64_t at = stored == 4 ? detzcode(p) : detzcode64(p); + sp->types[i] = at <= TIME_T_MAX; if (sp->types[i]) { time_t attime = ((TYPE_SIGNED(time_t) ? at < TIME_T_MIN : at < 0) ? TIME_T_MIN : at); + if (timecnt && attime <= sp->ats[timecnt - 1]) { if (attime < sp->ats[timecnt - 1]) @@ -783,6 +785,7 @@ static int tzload(FAR const char *name, for (i = 0; i < sp->timecnt; ++i) { unsigned char typ = *p++; + if (sp->typecnt <= typ) { goto oops; @@ -838,6 +841,7 @@ static int tzload(FAR const char *name, { int_fast64_t tr = stored == 4 ? detzcode(p) : detzcode64(p); int_fast32_t corr = detzcode(p + stored); + p += stored + 4; /* Leap seconds cannot occur before the Epoch, @@ -949,6 +953,7 @@ static int tzload(FAR const char *name, int gotabbr = 0; int charcnt = sp->charcnt; + for (i = 0; i < ts->typecnt; i++) { FAR char *tsabbr = ts->chars + ts->ttis[i].tt_desigidx; @@ -996,6 +1001,7 @@ static int tzload(FAR const char *name, for (i = 0; i < ts->timecnt && sp->timecnt < TZ_MAX_TIMES; i++) { time_t t = ts->ats[i]; + if (increment_overflow_time(&t, leapcorr(sp, t)) || (0 < sp->timecnt && t <= sp->ats[sp->timecnt - 1])) { @@ -1027,6 +1033,7 @@ static int tzload(FAR const char *name, { time_t repeatat = sp->ats[0] + SECSPERREPEAT; int repeattype = sp->types[0]; + for (i = 1; i < sp->timecnt; ++i) { if (sp->ats[i] == repeatat && @@ -1043,6 +1050,7 @@ static int tzload(FAR const char *name, { time_t repeatat = sp->ats[sp->timecnt - 1] - SECSPERREPEAT; int repeattype = sp->types[sp->timecnt - 1]; + for (i = sp->timecnt - 2; i >= 0; --i) { if (sp->ats[i] == repeatat && @@ -1403,80 +1411,82 @@ static int_fast32_t transtime(int year, leap_year = isleap(year); switch (rulep->r_type) { - case JULIAN_DAY: + case JULIAN_DAY: - /* Jn - Julian day, 1 == January 1, 60 == March 1 even in leap - * years. - * In non-leap years, or if the day number is 59 or less, just - * add SECSPERDAY times the day number-1 to the time of - * January 1, midnight, to get the day. - */ + /* Jn - Julian day, 1 == January 1, 60 == March 1 even in leap + * years. + * In non-leap years, or if the day number is 59 or less, just + * add SECSPERDAY times the day number-1 to the time of + * January 1, midnight, to get the day. + */ - value = (rulep->r_day - 1) * SECSPERDAY; - if (leap_year && rulep->r_day >= 60) - { - value += SECSPERDAY; - } + value = (rulep->r_day - 1) * SECSPERDAY; + if (leap_year && rulep->r_day >= 60) + { + value += SECSPERDAY; + } - break; + break; - case DAY_OF_YEAR: + case DAY_OF_YEAR: - /* n - day of year. - * Just add SECSPERDAY times the day number to the time of - * January 1, midnight, to get the day. - */ + /* n - day of year. + * Just add SECSPERDAY times the day number to the time of + * January 1, midnight, to get the day. + */ - value = rulep->r_day * SECSPERDAY; - break; + value = rulep->r_day * SECSPERDAY; + break; - case MONTH_NTH_DAY_OF_WEEK: + case MONTH_NTH_DAY_OF_WEEK: - /* Mm.n.d - nth "dth day" of month m */ + /* Mm.n.d - nth "dth day" of month m */ - /* Use Zeller's Congruence to get day-of-week of first day of - * month. - */ + /* Use Zeller's Congruence to get day-of-week of first day of + * month. + */ - m1 = (rulep->r_mon + 9) % 12 + 1; - yy0 = (rulep->r_mon <= 2) ? (year - 1) : year; - yy1 = yy0 / 100; - yy2 = yy0 % 100; - dow = ((26 * m1 - 2) / 10 + 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7; - if (dow < 0) - { - dow += DAYSPERWEEK; - } + m1 = (rulep->r_mon + 9) % 12 + 1; + yy0 = (rulep->r_mon <= 2) ? (year - 1) : year; + yy1 = yy0 / 100; + yy2 = yy0 % 100; + dow = ((26 * m1 - 2) / 10 + 1 + yy2 + yy2 / 4 + yy1 / 4 - + 2 * yy1) % 7; + if (dow < 0) + { + dow += DAYSPERWEEK; + } - /* "dow" is the day-of-week of the first day of the month. Get - * the day-of-month (zero-origin) of the first "dow" day of the - * month. - */ + /* "dow" is the day-of-week of the first day of the month. Get + * the day-of-month (zero-origin) of the first "dow" day of the + * month. + */ - d = rulep->r_day - dow; - if (d < 0) - { - d += DAYSPERWEEK; - } + d = rulep->r_day - dow; + if (d < 0) + { + d += DAYSPERWEEK; + } - for (i = 1; i < rulep->r_week; ++i) - { - if (d + DAYSPERWEEK >= g_mon_lengths[leap_year][rulep->r_mon - 1]) - { - break; - } + for (i = 1; i < rulep->r_week; ++i) + { + if (d + DAYSPERWEEK >= + g_mon_lengths[leap_year][rulep->r_mon - 1]) + { + break; + } - d += DAYSPERWEEK; - } + d += DAYSPERWEEK; + } - /* "d" is the day-of-month (zero-origin) of the day we want */ + /* "d" is the day-of-month (zero-origin) of the day we want */ - value = d * SECSPERDAY; - for (i = 0; i < rulep->r_mon - 1; ++i) - { - value += g_mon_lengths[leap_year][i] * SECSPERDAY; - } - break; + value = d * SECSPERDAY; + for (i = 0; i < rulep->r_mon - 1; ++i) + { + value += g_mon_lengths[leap_year][i] * SECSPERDAY; + } + break; } /* "value" is the year-relative time of 00:00:00 UT on the day in @@ -1710,9 +1720,11 @@ static int tzparse(FAR const char *name, FAR struct state_s *sp, yearsecs = (g_year_lengths[isleap(year)] * SECSPERDAY); int reversed = endtime < starttime; + if (reversed) { int_fast32_t swap = starttime; + starttime = endtime; endtime = swap; } @@ -2178,6 +2190,7 @@ static FAR struct tm *timesub(FAR const time_t *timep, if (!TYPE_SIGNED(time_t) && y < TM_YEAR_BASE) { int signed_y = y; + tmp->tm_year = signed_y - TM_YEAR_BASE; } else if ((!TYPE_SIGNED(time_t) || INT_MIN + TM_YEAR_BASE <= y) diff --git a/libs/libc/time/lib_strftime.c b/libs/libc/time/lib_strftime.c index c16a8611d64..e07c8c1777d 100644 --- a/libs/libc/time/lib_strftime.c +++ b/libs/libc/time/lib_strftime.c @@ -148,6 +148,7 @@ static int get_week_num(FAR const struct tm *time) int dec31 = (time->tm_wday + DAYSPERWEEK - time->tm_yday - 1) % DAYSPERWEEK; + if (dec31 == TM_THURSDAY || (dec31 == TM_FRIDAY && is_leap(time->tm_year % 400 - 1))) { @@ -161,6 +162,7 @@ static int get_week_num(FAR const struct tm *time) */ int jan1 = (time->tm_wday + 371 - time->tm_yday) % DAYSPERWEEK; + if (jan1 != TM_THURSDAY && (jan1 != TM_WEDNESDAY || !is_leap(time->tm_year))) { @@ -190,6 +192,7 @@ static int get_week_year(FAR const struct tm *time) { int week_num = get_week_num(time); int week_year = time->tm_year + TM_YEAR_BASE; + if (time->tm_yday < 3 && week_num != 1) { week_year--; @@ -297,462 +300,464 @@ size_t strftime(FAR char *s, size_t max, FAR const char *format, if (*format != '%') { - *dest++ = *format++; - chleft--; - continue; + *dest++ = *format++; + chleft--; + continue; } /* Handle the format character */ - format++; - len = 0; + format++; + len = 0; process_next: - switch (*format++) - { - /* Always-enabled conversion specifiers. */ - - /* %a: A three-letter abbreviation for the day of the week. */ - - case 'a': - { - if (tm->tm_wday < 7) - { - str = g_abbrev_wdayname[tm->tm_wday]; - len = snprintf(dest, chleft, "%s", str); - } - } - break; - - /* %h: Equivalent to %b */ - - case 'h': - - /* %b: The abbreviated month name according to the current - * locale. - */ - - case 'b': - { - if (tm->tm_mon < 12) - { - str = g_abbrev_monthname[tm->tm_mon]; - len = snprintf(dest, chleft, "%s", str); - } - } - break; - - /* %d: The day of the month as a decimal number - * (range 01 to 31). - */ - - case 'd': - { - len = snprintf(dest, chleft, "%02d", tm->tm_mday); - } - break; - - /* The 'E' or 'O' are modifier characters to indicate that an - * alternative format or specification should be used rather than - * the one normally used by unmodified conversion specifier. - * the following are the supported format: - * %Ec %EC %Ex %EX %Ey %EY - * %Od %oe %OH %OI %Om %OM - * %OS %Ou %OU %OV %Ow %OW %Oy - * If the alternative format or specification does not exist for - * current locale, then the behavior shall be same as the - * unmodified conversion specification, i.e the %Ec is same as %c - */ - - case 'E': - case 'O': - { - goto process_next; - } - - /* %H: The hour as a decimal number using a 24-hour clock - * (range 00 to 23). - */ - - case 'H': - { - len = snprintf(dest, chleft, "%02d", tm->tm_hour); - } - break; - - /* %m: The month as a decimal number (range 01 to 12). */ - - case 'm': - { - len = snprintf(dest, chleft, "%02d", tm->tm_mon + 1); - } - break; - - /* %M: The minute as a decimal number (range 00 to 59). */ - - case 'M': - { - len = snprintf(dest, chleft, "%02d", tm->tm_min); - } - break; - - /* %S: The second as a decimal number (range 00 to 60). - * (The range is up to 60 to allow for occasional leap seconds.) - */ - - case 'S': - { - len = snprintf(dest, chleft, "%02d", tm->tm_sec); - } - break; - - /* %Y: The year as a decimal number including the century. */ - - case 'Y': - { - len = snprintf(dest, chleft, "%04d", - tm->tm_year + TM_YEAR_BASE); - } - break; - - /* %%: A literal '%' character. */ - - case '%': - { - *dest = '%'; - len = 1; - } - break; + switch (*format++) + { + /* Always-enabled conversion specifiers. */ + + /* %a: A three-letter abbreviation for the day of the week. */ + + case 'a': + { + if (tm->tm_wday < 7) + { + str = g_abbrev_wdayname[tm->tm_wday]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; + + /* %h: Equivalent to %b */ + + case 'h': + + /* %b: The abbreviated month name according to the current + * locale. + */ + + case 'b': + { + if (tm->tm_mon < 12) + { + str = g_abbrev_monthname[tm->tm_mon]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; + + /* %d: The day of the month as a decimal number + * (range 01 to 31). + */ + + case 'd': + { + len = snprintf(dest, chleft, "%02d", tm->tm_mday); + } + break; + + /* The 'E' or 'O' are modifier characters to indicate that an + * alternative format or specification should be used rather than + * the one normally used by unmodified conversion specifier. + * the following are the supported format: + * %Ec %EC %Ex %EX %Ey %EY + * %Od %oe %OH %OI %Om %OM + * %OS %Ou %OU %OV %Ow %OW %Oy + * If the alternative format or specification does not exist for + * current locale, then the behavior shall be same as the + * unmodified conversion specification, i.e the %Ec is same as %c + */ + + case 'E': + case 'O': + { + goto process_next; + } + + /* %H: The hour as a decimal number using a 24-hour clock + * (range 00 to 23). + */ + + case 'H': + { + len = snprintf(dest, chleft, "%02d", tm->tm_hour); + } + break; + + /* %m: The month as a decimal number (range 01 to 12). */ + + case 'm': + { + len = snprintf(dest, chleft, "%02d", tm->tm_mon + 1); + } + break; + + /* %M: The minute as a decimal number (range 00 to 59). */ + + case 'M': + { + len = snprintf(dest, chleft, "%02d", tm->tm_min); + } + break; + + /* %S: The second as a decimal number (range 00 to 60). + * (The range is up to 60 to allow for occasional leap seconds.) + */ + + case 'S': + { + len = snprintf(dest, chleft, "%02d", tm->tm_sec); + } + break; + + /* %Y: The year as a decimal number including the century. */ + + case 'Y': + { + len = snprintf(dest, chleft, "%04d", + tm->tm_year + TM_YEAR_BASE); + } + break; + + /* %%: A literal '%' character. */ + + case '%': + { + *dest = '%'; + len = 1; + } + break; #ifdef CONFIG_LIBC_STRFTIME_C_STANDARD_FORMATS - /* ISO C conversion specifiers. */ - - /* %A: The full name for the day of the week. */ - - case 'A': - { - if (tm->tm_wday < 7) - { - str = g_wdayname[tm->tm_wday]; - len = snprintf(dest, chleft, "%s", str); - } - } - break; - - /* %B: The full month name according to the current locale. */ - - case 'B': - { - if (tm->tm_mon < 12) - { - str = g_monthname[tm->tm_mon]; - len = snprintf(dest, chleft, "%s", str); - } - } - break; - - /* %I: The hour as a decimal number using a 12-hour clock - * (range 01 to 12). - */ - - case 'I': - { - len = snprintf(dest, chleft, "%02d", (tm->tm_hour % 12) != 0 ? - (tm->tm_hour % 12) : 12); - } - break; - - /* %j: The day of the year as a decimal number - * (range 001 to 366). - */ - - case 'j': - { - if (tm->tm_mon < 12) - { - value = clock_daysbeforemonth(tm->tm_mon, - clock_isleapyear(tm->tm_year)) + tm->tm_mday; - len = snprintf(dest, chleft, "%03d", value); - } - } - break; - - /* %p: Either "AM" or "PM" according to the given time value. */ - - case 'p': - { - if (tm->tm_hour >= 12) - { - str = "PM"; - } - else - { - str = "AM"; - } - - len = snprintf(dest, chleft, "%s", str); - } - break; - - /* %U: Week number of the current year as a decimal number, - * (00-53). Starting with the first Sunday as the first day - * of week 01. - */ - - case 'U': - { - value = (tm->tm_yday + DAYSPERWEEK - tm->tm_wday) - / DAYSPERWEEK; - len = snprintf(dest, chleft, "%02d", value); - } - break; - - /* %w: The weekday as a decimal number (range 0 to 6). */ - - case 'w': - { - len = snprintf(dest, chleft, "%d", tm->tm_wday); - } - break; - - /* %W: Week number of the current year as a decimal number, - * (00-53). Starting with the first Monday as the first day - * of week 01. - */ - - case 'W': - { - value = (tm->tm_yday + DAYSPERWEEK - - (tm->tm_wday + 6) % DAYSPERWEEK) - / DAYSPERWEEK; - len = snprintf(dest, chleft, "%02d", value); - } - break; - - /* %x Locale date without time */ - - case 'x': - { - len = snprintf(dest, chleft, "%02d/%02d/%04d", - tm->tm_mon, tm->tm_mday, - tm->tm_year + TM_YEAR_BASE); - } - break; - - /* %X: Locale time without date */ - - case 'X': - { - len = snprintf(dest, chleft, "%02d:%02d:%02d", - tm->tm_hour, tm->tm_min, tm->tm_sec); - } - break; - - /* %y: The year as a decimal number without a century - * (range 00 to 99). - */ - - case 'y': - { - len = snprintf(dest, chleft, "%02d", tm->tm_year % 100); - } - break; + /* ISO C conversion specifiers. */ + + /* %A: The full name for the day of the week. */ + + case 'A': + { + if (tm->tm_wday < 7) + { + str = g_wdayname[tm->tm_wday]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; + + /* %B: The full month name according to the current locale. */ + + case 'B': + { + if (tm->tm_mon < 12) + { + str = g_monthname[tm->tm_mon]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; + + /* %I: The hour as a decimal number using a 12-hour clock + * (range 01 to 12). + */ + + case 'I': + { + len = snprintf(dest, chleft, "%02d", (tm->tm_hour % 12) != 0 ? + (tm->tm_hour % 12) : 12); + } + break; + + /* %j: The day of the year as a decimal number + * (range 001 to 366). + */ + + case 'j': + { + if (tm->tm_mon < 12) + { + value = clock_daysbeforemonth(tm->tm_mon, + clock_isleapyear(tm->tm_year)) + tm->tm_mday; + len = snprintf(dest, chleft, "%03d", value); + } + } + break; + + /* %p: Either "AM" or "PM" according to the given time value. */ + + case 'p': + { + if (tm->tm_hour >= 12) + { + str = "PM"; + } + else + { + str = "AM"; + } + + len = snprintf(dest, chleft, "%s", str); + } + break; + + /* %U: Week number of the current year as a decimal number, + * (00-53). Starting with the first Sunday as the first day + * of week 01. + */ + + case 'U': + { + value = (tm->tm_yday + DAYSPERWEEK - tm->tm_wday) + / DAYSPERWEEK; + len = snprintf(dest, chleft, "%02d", value); + } + break; + + /* %w: The weekday as a decimal number (range 0 to 6). */ + + case 'w': + { + len = snprintf(dest, chleft, "%d", tm->tm_wday); + } + break; + + /* %W: Week number of the current year as a decimal number, + * (00-53). Starting with the first Monday as the first day + * of week 01. + */ + + case 'W': + { + value = (tm->tm_yday + DAYSPERWEEK - + (tm->tm_wday + 6) % DAYSPERWEEK) + / DAYSPERWEEK; + len = snprintf(dest, chleft, "%02d", value); + } + break; + + /* %x Locale date without time */ + + case 'x': + { + len = snprintf(dest, chleft, "%02d/%02d/%04d", + tm->tm_mon, tm->tm_mday, + tm->tm_year + TM_YEAR_BASE); + } + break; + + /* %X: Locale time without date */ + + case 'X': + { + len = snprintf(dest, chleft, "%02d:%02d:%02d", + tm->tm_hour, tm->tm_min, tm->tm_sec); + } + break; + + /* %y: The year as a decimal number without a century + * (range 00 to 99). + */ + + case 'y': + { + len = snprintf(dest, chleft, "%02d", tm->tm_year % 100); + } + break; #endif #ifdef CONFIG_LIBC_STRFTIME_POSIX_FORMATS - /* POSIX conversion specifiers beyond ISO C. */ - - /* %C: The century number (year/100) as a 2-digit integer. */ - - case 'C': - { - len = snprintf(dest, chleft, "%02d", tm->tm_year / 100); - } - break; - - /* %e: Like %d, the day of the month as a decimal number, but - * a leading zero is replaced by a space. - */ - - case 'e': - { - len = snprintf(dest, chleft, "%2d", tm->tm_mday); - } - break; - - /* %F: ISO 8601 date format: "%Y-%m-%d" */ - - case 'F': - { - len = snprintf(dest, chleft, "%04d-%02d-%02d", - tm->tm_year + TM_YEAR_BASE, tm->tm_mon + 1, - tm->tm_mday); - } - break; - - /* %g: 2-digit year version of %G, (00-99) */ - - case 'g': - { - value = get_week_year(tm) % 100; - len = snprintf(dest, chleft, "%02d", value); - } - break; - - /* %G: ISO 8601 week based year */ - - case 'G': - { - len = snprintf(dest, chleft, "%04d", get_week_year(tm)); - } - break; - - /* %n: A newline character. */ - - case 'n': - { - *dest = '\n'; - len = 1; - } - break; - - /* %r: 12-hour clock time */ - - case 'r': - { - if (tm->tm_hour >= 12) - { - str = "pm"; - } - else - { - str = "am"; - } - - value = tm->tm_hour == 12 ? - tm->tm_hour == 12 : - tm->tm_hour % (HOURSPERDAY / 2); - - len = snprintf(dest, chleft, "%02d:%02d:%02d %s", - value, tm->tm_min, tm->tm_sec, str); - } - break; - - /* %R: Shortcut for %H:%M. */ - - case 'R': - { - len = snprintf(dest, chleft, "%02d:%02d", - tm->tm_hour, tm->tm_min); - } - break; - - /* %t: A tab character. */ - - case 't': - { - *dest = '\t'; - len = 1; - } - break; - - /* %T: Shortcut for %H:%M:%S. */ - - case 'T': - { - len = snprintf(dest, chleft, "%02d:%02d:%02d", - tm->tm_hour, tm->tm_min, tm->tm_sec); - } - break; - - /* %u: The day of the week as a decimal, (1-7). Monday being 1, - * Sunday being 0. - */ - - case 'u': - { - value = tm->tm_wday == 0 ? 7 : tm->tm_wday; - len = snprintf(dest, chleft, "%d", value); - } - break; - - /* %V: ISO 8601 week number */ - - case 'V': - { - value = get_week_num(tm); - len = snprintf(dest, chleft, "%02d", value); - } - break; - - /* %z: Numeric timezone as hour and minute offset from UTC - * "+hhmm" or "-hhmm" - */ - - case 'z': - { - int hour = tm->tm_gmtoff / 3600; - int min = tm->tm_gmtoff % 3600 / 60; - int utc_val = hour * 100 + min; - len = snprintf(dest, chleft, "+%04d", utc_val); - } - break; + /* POSIX conversion specifiers beyond ISO C. */ + + /* %C: The century number (year/100) as a 2-digit integer. */ + + case 'C': + { + len = snprintf(dest, chleft, "%02d", tm->tm_year / 100); + } + break; + + /* %e: Like %d, the day of the month as a decimal number, but + * a leading zero is replaced by a space. + */ + + case 'e': + { + len = snprintf(dest, chleft, "%2d", tm->tm_mday); + } + break; + + /* %F: ISO 8601 date format: "%Y-%m-%d" */ + + case 'F': + { + len = snprintf(dest, chleft, "%04d-%02d-%02d", + tm->tm_year + TM_YEAR_BASE, tm->tm_mon + 1, + tm->tm_mday); + } + break; + + /* %g: 2-digit year version of %G, (00-99) */ + + case 'g': + { + value = get_week_year(tm) % 100; + len = snprintf(dest, chleft, "%02d", value); + } + break; + + /* %G: ISO 8601 week based year */ + + case 'G': + { + len = snprintf(dest, chleft, "%04d", get_week_year(tm)); + } + break; + + /* %n: A newline character. */ + + case 'n': + { + *dest = '\n'; + len = 1; + } + break; + + /* %r: 12-hour clock time */ + + case 'r': + { + if (tm->tm_hour >= 12) + { + str = "pm"; + } + else + { + str = "am"; + } + + value = tm->tm_hour == 12 ? + tm->tm_hour == 12 : + tm->tm_hour % (HOURSPERDAY / 2); + + len = snprintf(dest, chleft, "%02d:%02d:%02d %s", + value, tm->tm_min, tm->tm_sec, str); + } + break; + + /* %R: Shortcut for %H:%M. */ + + case 'R': + { + len = snprintf(dest, chleft, "%02d:%02d", + tm->tm_hour, tm->tm_min); + } + break; + + /* %t: A tab character. */ + + case 't': + { + *dest = '\t'; + len = 1; + } + break; + + /* %T: Shortcut for %H:%M:%S. */ + + case 'T': + { + len = snprintf(dest, chleft, "%02d:%02d:%02d", + tm->tm_hour, tm->tm_min, tm->tm_sec); + } + break; + + /* %u: The day of the week as a decimal, (1-7). Monday being 1, + * Sunday being 0. + */ + + case 'u': + { + value = tm->tm_wday == 0 ? 7 : tm->tm_wday; + len = snprintf(dest, chleft, "%d", value); + } + break; + + /* %V: ISO 8601 week number */ + + case 'V': + { + value = get_week_num(tm); + len = snprintf(dest, chleft, "%02d", value); + } + break; + + /* %z: Numeric timezone as hour and minute offset from UTC + * "+hhmm" or "-hhmm" + */ + + case 'z': + { + int hour = tm->tm_gmtoff / 3600; + int min = tm->tm_gmtoff % 3600 / 60; + int utc_val = hour * 100 + min; + + len = snprintf(dest, chleft, "+%04d", utc_val); + } + break; #endif #ifdef CONFIG_LIBC_STRFTIME_NONSTANDARD_FORMATS - /* Non-standard conversion specifiers. */ - - /* %k: The hour (24-hour clock) as a decimal number - * (range 0 to 23); - * single digits are preceded by a blank. - */ - - case 'k': - { - len = snprintf(dest, chleft, "%2d", tm->tm_hour); - } - break; - - /* %l: The hour (12-hour clock) as a decimal number - * (range 1 to 12); - * single digits are preceded by a blank. - */ - - case 'l': - { - len = snprintf(dest, chleft, "%2d", (tm->tm_hour % 12) != 0 ? - (tm->tm_hour % 12) : 12); - } - break; - - /* %P: Like %p but in lowercase: "am" or "pm" */ - - case 'P': - { - if (tm->tm_hour >= 12) - { - str = "pm"; - } - else - { - str = "am"; - } - - len = snprintf(dest, chleft, "%s", str); - } - break; - - /* %s: The number of seconds since the Epoch, that is, - * since 1970-01-01 00:00:00 UTC. - * Hmmm... mktime argume is not 'const'. - */ - - case 's': - { - struct tm tmp = *tm; - len = snprintf(dest, chleft, "%ju", (uintmax_t)mktime(&tmp)); - } - break; + /* Non-standard conversion specifiers. */ + + /* %k: The hour (24-hour clock) as a decimal number + * (range 0 to 23); + * single digits are preceded by a blank. + */ + + case 'k': + { + len = snprintf(dest, chleft, "%2d", tm->tm_hour); + } + break; + + /* %l: The hour (12-hour clock) as a decimal number + * (range 1 to 12); + * single digits are preceded by a blank. + */ + + case 'l': + { + len = snprintf(dest, chleft, "%2d", (tm->tm_hour % 12) != 0 ? + (tm->tm_hour % 12) : 12); + } + break; + + /* %P: Like %p but in lowercase: "am" or "pm" */ + + case 'P': + { + if (tm->tm_hour >= 12) + { + str = "pm"; + } + else + { + str = "am"; + } + + len = snprintf(dest, chleft, "%s", str); + } + break; + + /* %s: The number of seconds since the Epoch, that is, + * since 1970-01-01 00:00:00 UTC. + * Hmmm... mktime argume is not 'const'. + */ + + case 's': + { + struct tm tmp = *tm; + + len = snprintf(dest, chleft, "%ju", (uintmax_t)mktime(&tmp)); + } + break; #endif } diff --git a/libs/libc/unistd/lib_confstr.c b/libs/libc/unistd/lib_confstr.c index c00697746b8..1016b588cdd 100644 --- a/libs/libc/unistd/lib_confstr.c +++ b/libs/libc/unistd/lib_confstr.c @@ -71,9 +71,9 @@ size_t confstr(int name, FAR char *buf, size_t len) break; } - /* Programming environment is not supported on NuttX, so all - * _CS_POSIX_V6 configuration variables are empty. - */ + /* Programming environment is not supported on NuttX, so all + * _CS_POSIX_V6 configuration variables are empty. + */ case _CS_POSIX_V6_ILP32_OFF32_CFLAGS: case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS: diff --git a/libs/libc/unistd/lib_crypt_r.c b/libs/libc/unistd/lib_crypt_r.c index 91bf8ad73b8..3fac5a5d3fa 100644 --- a/libs/libc/unistd/lib_crypt_r.c +++ b/libs/libc/unistd/lib_crypt_r.c @@ -105,6 +105,7 @@ static int md5_update(FAR cryptodev_context_t *ctx, FAR const void *input, size_t ilen) { int ret; + ctx->crypt.op = COP_ENCRYPT; ctx->crypt.flags |= COP_FLAG_UPDATE; ctx->crypt.src = (caddr_t)input; diff --git a/libs/libc/unistd/lib_daemon.c b/libs/libc/unistd/lib_daemon.c index b9e11d24ca9..ec33c3d1795 100644 --- a/libs/libc/unistd/lib_daemon.c +++ b/libs/libc/unistd/lib_daemon.c @@ -104,6 +104,7 @@ int daemon(int nochdir, int noclose) if (nochdir == 0) { int ret = chdir("/"); + if (ret < 0) { return -1; /* chdir() will set the errno variable */ @@ -114,6 +115,7 @@ int daemon(int nochdir, int noclose) if (noclose == 0) { int fd = open("/dev/null", O_RDWR); + if (fd < 0) { return -1; diff --git a/libs/libc/unistd/lib_getopt_common.c b/libs/libc/unistd/lib_getopt_common.c index 404c27e577f..5e8c669af55 100644 --- a/libs/libc/unistd/lib_getopt_common.c +++ b/libs/libc/unistd/lib_getopt_common.c @@ -168,18 +168,18 @@ static int getopt_long_option(FAR struct getopt_s *go, FAR char *next; case no_argument: - /* No, no arguments. Just return the argument that we - * found. - */ + /* No, no arguments. Just return the argument that we + * found. + */ go->go_optptr = NULL; go->go_optind++; break; case optional_argument: - /* Check if there is a following argument and if that - * following argument is another option. - */ + /* Check if there is a following argument and if that + * following argument is another option. + */ next = argv[go->go_optind + 1]; if (next == NULL || next[0] == '-') @@ -345,6 +345,7 @@ int getopt_common(int argc, FAR char * const argv[], /* Get thread-specific getopt() variables */ FAR struct getopt_s *go = getoptvars(); + if (go == NULL) { return '?'; diff --git a/libs/libc/unistd/lib_getoptargp.c b/libs/libc/unistd/lib_getoptargp.c index 02ff2a7c3da..22da0ddc00d 100644 --- a/libs/libc/unistd/lib_getoptargp.c +++ b/libs/libc/unistd/lib_getoptargp.c @@ -44,5 +44,6 @@ FAR char **getoptargp(void) { FAR struct getopt_s *go = getoptvars(); + return &go->go_optarg; } diff --git a/libs/libc/unistd/lib_getopterrp.c b/libs/libc/unistd/lib_getopterrp.c index 9d6f5311b75..fe38cf34dd5 100644 --- a/libs/libc/unistd/lib_getopterrp.c +++ b/libs/libc/unistd/lib_getopterrp.c @@ -44,5 +44,6 @@ FAR int *getopterrp(void) { FAR struct getopt_s *go = getoptvars(); + return &go->go_opterr; } diff --git a/libs/libc/unistd/lib_getoptindp.c b/libs/libc/unistd/lib_getoptindp.c index 596208e4b22..3264741bcf4 100644 --- a/libs/libc/unistd/lib_getoptindp.c +++ b/libs/libc/unistd/lib_getoptindp.c @@ -44,5 +44,6 @@ int *getoptindp(void) { FAR struct getopt_s *go = getoptvars(); + return &go->go_optind; } diff --git a/libs/libc/unistd/lib_getoptoptp.c b/libs/libc/unistd/lib_getoptoptp.c index fb529330d0d..fb3cf553b25 100644 --- a/libs/libc/unistd/lib_getoptoptp.c +++ b/libs/libc/unistd/lib_getoptoptp.c @@ -44,5 +44,6 @@ int *getoptoptp(void) { FAR struct getopt_s *go = getoptvars(); + return &go->go_optopt; } diff --git a/libs/libc/unistd/lib_ulimit.c b/libs/libc/unistd/lib_ulimit.c index ddf56b4a4e9..4449a5ac077 100644 --- a/libs/libc/unistd/lib_ulimit.c +++ b/libs/libc/unistd/lib_ulimit.c @@ -55,6 +55,7 @@ long ulimit(int cmd, long newlimit) case UL_GETFSIZE: { struct rlimit rlp; + getrlimit(RLIMIT_FSIZE, &rlp); ret = rlp.rlim_cur / 512UL; } @@ -62,6 +63,7 @@ long ulimit(int cmd, long newlimit) case UL_SETFSIZE: { struct rlimit rlp; + rlp.rlim_max = RLIM_INFINITY; rlp.rlim_cur = newlimit * 512UL; ret = setrlimit(RLIMIT_FSIZE, &rlp); diff --git a/libs/libc/userfs/lib_userfs.c b/libs/libc/userfs/lib_userfs.c index 5653c28e874..efb47d24133 100644 --- a/libs/libc/userfs/lib_userfs.c +++ b/libs/libc/userfs/lib_userfs.c @@ -855,6 +855,7 @@ static inline int userfs_destroy_dispatch(FAR struct userfs_info_s *info, if (nsent < 0) { int ret = -get_errno(); + ferr("ERROR: sendto failed: %d\n", ret); return ret; } diff --git a/libs/libc/wchar/lib_wcscpy.c b/libs/libc/wchar/lib_wcscpy.c index 649233d4891..d36e8ff7c4d 100644 --- a/libs/libc/wchar/lib_wcscpy.c +++ b/libs/libc/wchar/lib_wcscpy.c @@ -53,6 +53,7 @@ FAR wchar_t *wcscpy(FAR wchar_t *d, FAR const wchar_t *s) { FAR wchar_t *a = d; + while ((*d++ = *s++)); return a; } diff --git a/libs/libc/wchar/lib_wcsrchr.c b/libs/libc/wchar/lib_wcsrchr.c index 59968e675f9..0696492293f 100644 --- a/libs/libc/wchar/lib_wcsrchr.c +++ b/libs/libc/wchar/lib_wcsrchr.c @@ -53,6 +53,7 @@ FAR wchar_t *wcsrchr(FAR const wchar_t *s, wchar_t c) { FAR const wchar_t *p; + for (p = s + wcslen(s); p >= s && *p != c; p--); return p >= s ? (FAR wchar_t *)p : 0; diff --git a/libs/libc/wchar/lib_wcsspn.c b/libs/libc/wchar/lib_wcsspn.c index 36a0d859c33..f1d09ae82e5 100644 --- a/libs/libc/wchar/lib_wcsspn.c +++ b/libs/libc/wchar/lib_wcsspn.c @@ -54,6 +54,7 @@ size_t wcsspn(FAR const wchar_t *s, FAR const wchar_t *c) { FAR const wchar_t *a; + for (a = s; *s && wcschr(c, *s); s++); return s - a; } diff --git a/libs/libc/wchar/lib_wcswidth.c b/libs/libc/wchar/lib_wcswidth.c index 06ce908c2cc..cb4c2cf4287 100644 --- a/libs/libc/wchar/lib_wcswidth.c +++ b/libs/libc/wchar/lib_wcswidth.c @@ -57,6 +57,7 @@ int wcswidth(FAR const wchar_t *wcs, size_t n) { int l = 0; int k = 0; + for (; n-- && *wcs && (k = wcwidth(*wcs)) >= 0; l += k, wcs++); return k < 0 ? k : l; diff --git a/libs/libc/wctype/lib_iswctype.c b/libs/libc/wctype/lib_iswctype.c index ec4932677cf..3f7d755d79b 100644 --- a/libs/libc/wctype/lib_iswctype.c +++ b/libs/libc/wctype/lib_iswctype.c @@ -110,44 +110,44 @@ int iswctype(wint_t c, wctype_t desc) { switch (desc) { - case WC_ALNUM: - return iswalnum(c); + case WC_ALNUM: + return iswalnum(c); - case WC_ALPHA: - return iswalpha(c); + case WC_ALPHA: + return iswalpha(c); - case WC_BLANK: - return iswblank(c); + case WC_BLANK: + return iswblank(c); - case WC_CNTRL: - return iswcntrl(c); + case WC_CNTRL: + return iswcntrl(c); - case WC_DIGIT: - return iswdigit(c); + case WC_DIGIT: + return iswdigit(c); - case WC_GRAPH: - return iswgraph(c); + case WC_GRAPH: + return iswgraph(c); - case WC_LOWER: - return iswlower(c); + case WC_LOWER: + return iswlower(c); - case WC_PRINT: - return iswprint(c); + case WC_PRINT: + return iswprint(c); - case WC_PUNCT: - return iswpunct(c); + case WC_PUNCT: + return iswpunct(c); - case WC_SPACE: - return iswspace(c); + case WC_SPACE: + return iswspace(c); - case WC_UPPER: - return iswupper(c); + case WC_UPPER: + return iswupper(c); - case WC_XDIGIT: - return iswxdigit(c); + case WC_XDIGIT: + return iswxdigit(c); - default: - break; /* eliminate warning */ + default: + break; /* eliminate warning */ } /* Otherwise unknown */ diff --git a/libs/libc/wctype/lib_wctype.c b/libs/libc/wctype/lib_wctype.c index 607de8c53f2..b786ea1c5e9 100644 --- a/libs/libc/wctype/lib_wctype.c +++ b/libs/libc/wctype/lib_wctype.c @@ -48,93 +48,93 @@ wctype_t wctype(FAR const char *c) { switch (*c) { - case 'a': - if (!strcmp(c, "alnum")) - { - return WC_ALNUM; - } - else if (!strcmp(c, "alpha")) - { - return WC_ALPHA; - } - - break; - - case 'b': - if (!strcmp(c, "blank")) - { - return WC_BLANK; - } - - break; - - case 'c': - if (!strcmp(c, "cntrl")) - { - return WC_CNTRL; - } - - break; - - case 'd': - if (!strcmp(c, "digit")) - { - return WC_DIGIT; - } - - break; - - case 'g': - if (!strcmp(c, "graph")) - { - return WC_GRAPH; - } - - break; - - case 'l': - if (!strcmp(c, "lower")) - { - return WC_LOWER; - } - - break; - - case 'p': - if (!strcmp(c, "print")) - { - return WC_PRINT; - } - else if (!strcmp(c, "punct")) - { - return WC_PUNCT; - } - - break; - - case 's': - if (!strcmp(c, "space")) - { - return WC_SPACE; - } - - break; - - case 'u': - if (!strcmp(c, "upper")) - { - return WC_UPPER; - } - - break; - - case 'x': - if (!strcmp(c, "xdigit")) - { - return WC_XDIGIT; - } - - break; + case 'a': + if (!strcmp(c, "alnum")) + { + return WC_ALNUM; + } + else if (!strcmp(c, "alpha")) + { + return WC_ALPHA; + } + + break; + + case 'b': + if (!strcmp(c, "blank")) + { + return WC_BLANK; + } + + break; + + case 'c': + if (!strcmp(c, "cntrl")) + { + return WC_CNTRL; + } + + break; + + case 'd': + if (!strcmp(c, "digit")) + { + return WC_DIGIT; + } + + break; + + case 'g': + if (!strcmp(c, "graph")) + { + return WC_GRAPH; + } + + break; + + case 'l': + if (!strcmp(c, "lower")) + { + return WC_LOWER; + } + + break; + + case 'p': + if (!strcmp(c, "print")) + { + return WC_PRINT; + } + else if (!strcmp(c, "punct")) + { + return WC_PUNCT; + } + + break; + + case 's': + if (!strcmp(c, "space")) + { + return WC_SPACE; + } + + break; + + case 'u': + if (!strcmp(c, "upper")) + { + return WC_UPPER; + } + + break; + + case 'x': + if (!strcmp(c, "xdigit")) + { + return WC_XDIGIT; + } + + break; } return 0;
