I do strncpy from one buff to another. On some length of source buffer in the second buffer appears additional characters at the end. Code is very simple and clear:
len=strlen(argv[2]);
param=(char*)malloc(sizeof(char*)*(len+1));
strcpy(param,argv[2]);
confname=strrchr(param,'/')+1;
len1=strlen(confname);
printf("Argument - %s\n",param);
strncpy(confpath,param,(len-len1));
printf("confpath %s\n",confpath);
______________________________________________
Result:
Argument - /home/vsergeev/usr/local/conf1/sazc.conf
confpath /home/vsergeev/usr/local/conf1PC
Argument - /home/vsergeev/usr/local/conf12/sazc.conf
confpath /home/vsergeev/usr/local/conf12/\PC
Argument - /home/vsergeev/usr/local/conf1234567890/sazc.conf
confpath /home/vsergeev/usr/local/conf1234567890/C
Argument -/home/vsergeev/usr/local/conf12345678901/sazc.conf
confpath /home/vsergeev/usr/local/conf12345678901/
len=strlen(argv[2]);
param=(char*)malloc(sizeof(char*)*(len+1));
strcpy(param,argv[2]);
confname=strrchr(param,'/')+1;
len1=strlen(confname);
printf("Argument - %s\n",param);
strncpy(confpath,param,(len-len1));
printf("confpath %s\n",confpath);
______________________________________________
Result:
Argument - /home/vsergeev/usr/local/conf1/sazc.conf
confpath /home/vsergeev/usr/local/conf1PC
Argument - /home/vsergeev/usr/local/conf12/sazc.conf
confpath /home/vsergeev/usr/local/conf12/\PC
Argument - /home/vsergeev/usr/local/conf1234567890/sazc.conf
confpath /home/vsergeev/usr/local/conf1234567890/C
Argument -/home/vsergeev/usr/local/conf12345678901/sazc.conf
confpath /home/vsergeev/usr/local/conf12345678901/