~aritra1911/mc_client

70583e54c52033cb094481c198a10b651d528257 — Aritra Sarkar 1 year, 7 months ago 62bec7f 16-bit_header
Fix : Handle `strtok_r()` returning null pointers on FreeBSD
1 files changed, 9 insertions(+), 7 deletions(-)

M commands.c
M commands.c => commands.c +9 -7
@@ 39,14 39,16 @@ append_header(SendCode snd_code, char *buf, char *rem, size_t len,

    head = 0;   /* Clear your head of all thoughts */

    memcpy(pending->content, rem, len);
    if ( rem )
        memcpy(pending->content, rem, len);
    pending->content[len] = '\0';

    /*
     * Overwrite buf with the `rem` pointer poiting to the start of the
     * Overwrite buf with the `rem` pointer pointing to the start of the
     * remaining message content.  Also hold the same in pending.
     */
    memmove(buf + sizeof(header_t), rem, len);
    if ( rem )
        memmove(buf + sizeof(header_t), rem, len);
    new_len = sizeof(header_t) + len;

    SET_CODE(head, snd_code);


@@ 70,7 72,7 @@ set_nick(const char *nick, char *buf, char *rem, size_t len,
    strncpy(new_nick, strtok_r(NULL, DELIM, &rem), MIN((size_t) NICKLEN, len));

    /* Report syntax error if additional arguments are specified */
    if ( *rem ) {
    if ( rem && *rem ) {
        if ( why )
            *why = EXTRA_ARGS;
        return -1;


@@ 193,7 195,7 @@ parse_command(char *nick, char *buf, size_t len, Message **pending,
     * Yes, we're taking difference between pointers here!
     * WARNING: Do not try this at home.
     */
    len -= rem - buf;
    len = rem ? len - (rem - buf) : 0;

    if ( !strcmp(command, "/setnick") ) {
        if ( help )


@@ 201,7 203,7 @@ parse_command(char *nick, char *buf, size_t len, Message **pending,
                          "Your nick can't have spaces in them either.",
                    command);

        if ( !*rem ) {
        if ( !rem || !*rem ) {
            if ( why )
                *why = REQ_ARG;
            return -1;


@@ 215,7 217,7 @@ parse_command(char *nick, char *buf, size_t len, Message **pending,
            sprintf(help, "`%s` must be followed by an action (message)",
                    command);

        if ( !*rem ) {
        if ( !rem || !*rem ) {
            if ( why )
                *why = REQ_ARG;
            return -1;