Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 6700ee2 in mainline


Ignore:
Timestamp:
2009-04-14T19:31:12Z (13 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master
Children:
17646b1
Parents:
4482bc7
Message:

Forbid destination string buffers of size zero altogether as they most probably indicate programming error.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/lib/string.c

    r4482bc7 r6700ee2  
    109109#include <errno.h>
    110110#include <align.h>
     111#include <debug.h>
    111112
    112113/** Byte mask consisting of lowest @n bits (out of 8) */
     
    537538 *
    538539 * @param dst   Destination buffer.
    539  * @param count Size of the destination buffer.
     540 * @param count Size of the destination buffer (must be > 0).
    540541 * @param src   Source string.
    541542 */
     
    546547        size_t dest_off;
    547548
    548         /* No space for the NULL-terminator in the buffer. */
    549         if (size == 0)
    550                 return;
     549        /* There must be space for a null terminator in the buffer. */
     550        ASSERT(size > 0);
    551551       
    552552        src_off = 0;
     
    563563/** Copy size-limited substring.
    564564 *
    565  * Copy source string @a src to destination buffer @a dest.
    566  * No more than @a size bytes are written. If the size of the output buffer
    567  * is at least one byte, the output string will always be well-formed, i.e.
    568  * null-terminated and containing only complete characters.
     565 * Copy prefix of string @a src of max. size @a size to destination buffer
     566 * @a dest. No more than @a size bytes are written. The output string will
     567 * always be well-formed, i.e. null-terminated and containing only complete
     568 * characters.
    569569 *
    570570 * No more than @a n bytes are read from the input string, so it does not
     
    572572 *
    573573 * @param dst   Destination buffer.
    574  * @param count Size of the destination buffer.
     574 * @param count Size of the destination buffer (must be > 0).
    575575 * @param src   Source string.
     576 * @param n     Maximum number of bytes to read from @a src.
    576577 */
    577578void str_ncpy(char *dest, size_t size, const char *src, size_t n)
     
    581582        size_t dest_off;
    582583
    583         /* No space for the null terminator in the buffer. */
    584         if (size == 0)
    585                 return;
     584        /* There must be space for a null terminator in the buffer. */
     585        ASSERT(size > 0);
    586586       
    587587        src_off = 0;
  • uspace/lib/libc/generic/string.c

    r4482bc7 r6700ee2  
    3636#include <string.h>
    3737#include <stdlib.h>
     38#include <assert.h>
    3839#include <limits.h>
    3940#include <ctype.h>
     
    471472 *
    472473 * @param dst   Destination buffer.
    473  * @param count Size of the destination buffer.
     474 * @param count Size of the destination buffer (must be > 0).
    474475 * @param src   Source string.
    475476 */
     
    480481        size_t dest_off;
    481482
    482         /* No space for the NULL-terminator in the buffer. */
    483         if (size == 0)
    484                 return;
     483        /* There must be space for a null terminator in the buffer. */
     484        assert(size > 0);
    485485       
    486486        src_off = 0;
     
    497497/** Copy size-limited substring.
    498498 *
    499  * Copy source string @a src to destination buffer @a dest.
    500  * No more than @a size bytes are written. If the size of the output buffer
    501  * is at least one byte, the output string will always be well-formed, i.e.
    502  * null-terminated and containing only complete characters.
     499 * Copy prefix of string @a src of max. size @a size to destination buffer
     500 * @a dest. No more than @a size bytes are written. The output string will
     501 * always be well-formed, i.e. null-terminated and containing only complete
     502 * characters.
    503503 *
    504504 * No more than @a n bytes are read from the input string, so it does not
     
    506506 *
    507507 * @param dst   Destination buffer.
    508  * @param count Size of the destination buffer.
     508 * @param count Size of the destination buffer (must be > 0).
    509509 * @param src   Source string.
     510 * @param n     Maximum number of bytes to read from @a src.
    510511 */
    511512void str_ncpy(char *dest, size_t size, const char *src, size_t n)
     
    515516        size_t dest_off;
    516517
    517         /* No space for the null terminator in the buffer. */
    518         if (size == 0)
    519                 return;
     518        /* There must be space for a null terminator in the buffer. */
     519        assert(size > 0);
    520520       
    521521        src_off = 0;
Note: See TracChangeset for help on using the changeset viewer.