Re: [fossil-users] Bug? fossil_strndup is not added terminating null byte ('\0')

2017-06-08 Thread Richard Hipp
On 6/8/17, kowlsd3pw...@yahoo.co.jp  wrote:
>
>
> strndup is added terminating null byte.
> but Fossil_strndup behaves as strncpy.
> fossil_strndup not added terminating null byte ('\0') when len>=0

Good catch.  That is only used in one place in the code, but it is
significant.  A fix has been checked in.

-- 
D. Richard Hipp
d...@sqlite.org
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


[fossil-users] Bug? fossil_strndup is not added terminating null byte ('\0')

2017-06-08 Thread kowlsd3pw23s


strndup is added terminating null byte.
but Fossil_strndup behaves as strncpy.
fossil_strndup not added terminating null byte ('\0') when len>=0

src/import.c : fossil_strndup
https://www.fossil-scm.org/index.html/artifact?ln=91=14ebf8376b92b944
    z[n] = '\0';


test code  

Insert the code somewhere in src/*.c and recompile.

make clean && make
./fossil test-fossil_strndup

result 
strlen(fossil_strndup("0123456789", 0)) : 2
assertion "strlen(p)==i" failed:

test code  

/*
** COMMAND: test-fossil_strndup
**
** Help text goes here.
*/
void test_fossil_strndup_cmd(void){
  for(int i=0; i<=5; i++){
    char *p = fossil_strndup("0123456789", i);
    if (strlen(p)!=i)
  printf("strlen(fossil_strndup(\"0123456789\", %d)) : %d\n",i,strlen(p));
    assert(strlen(p)==i);
    free(p);
  }
  printf("ok\n");
}___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users