1/* 2** Copyright (C) 2010-2012 Erik de Castro Lopo <erikd@mega-nerd.com> 3** 4** This program is free software; you can redistribute it and/or modify 5** it under the terms of the GNU Lesser General Public License as published by 6** the Free Software Foundation; either version 2.1 of the License, or 7** (at your option) any later version. 8** 9** This program is distributed in the hope that it will be useful, 10** but WITHOUT ANY WARRANTY; without even the implied warranty of 11** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12** GNU Lesser General Public License for more details. 13** 14** You should have received a copy of the GNU Lesser General Public License 15** along with this program; if not, write to the Free Software 16** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17*/ 18 19#include "sfconfig.h" 20 21#include <stdio.h> 22#include <stdlib.h> 23 24#include "common.h" 25 26#include "test_main.h" 27 28void 29test_psf_strlcpy_crlf (void) 30{ const char *src = "a\nb\nc\n" ; 31 char *dest ; 32 int dest_len ; 33 34 print_test_name ("Testing psf_strlcpy_crlf") ; 35 36 for (dest_len = 3 ; dest_len < 30 ; dest_len++) 37 { dest = calloc (1, dest_len + 1) ; 38 if (dest == NULL) 39 { printf ("\n\nLine %d: calloc failed!\n\n", __LINE__) ; 40 exit (1) ; 41 } ; 42 43 /* This value needs to be a in the [0, 127] range to avoid tripping up 44 ** compiles like Sun Studio 12.* 45 */ 46 dest [dest_len] = '\x5a' ; 47 48 psf_strlcpy_crlf (dest, src, dest_len, sizeof (*src)) ; 49 50 if (dest [dest_len] != '\x5a') 51 { printf ("\n\nLine %d: buffer overrun for dest_len == %d\n\n", __LINE__, dest_len) ; 52 exit (1) ; 53 } ; 54 55 free (dest) ; 56 } ; 57 58 puts ("ok") ; 59} /* test_psf_strlcpy_crlf */ 60