updated file io test to avoid crash
This commit is contained in:
@ -133,7 +133,7 @@ namespace ams
|
||||
{
|
||||
int ret = amsstring_success;
|
||||
ams_chartype *newcstring = NULL;
|
||||
int I;
|
||||
int I = 0;
|
||||
|
||||
_newlen = (_newlen<0) ? 0 : _newlen;
|
||||
|
||||
@ -145,6 +145,10 @@ namespace ams
|
||||
return ret;
|
||||
}
|
||||
|
||||
for(I=0;I<(_newlen+1);I++) //init entire string to '\0' - slower, but valgrind complains less
|
||||
{
|
||||
newcstring[I] = (ams_chartype) '\0';
|
||||
}
|
||||
if(cstring!=NULL)
|
||||
{
|
||||
for(I=0;I<(_newlen+1) && I<(length+1);I++)
|
||||
@ -152,10 +156,10 @@ namespace ams
|
||||
newcstring[I] = cstring[I];
|
||||
}
|
||||
}
|
||||
for(I=length;I<(_newlen+1);I++)
|
||||
{
|
||||
newcstring[I] = (ams_chartype) '\0';
|
||||
}
|
||||
// for(I=length;I<(_newlen+1);I++) //init only new portion of string to '\0' - valgrind complains?
|
||||
// {
|
||||
// newcstring[I] = (ams_chartype) '\0';
|
||||
// }
|
||||
|
||||
newcstring[_newlen] = '\0';
|
||||
|
||||
@ -1402,7 +1406,11 @@ namespace ams
|
||||
{
|
||||
const int BUFFSZ = 8000;
|
||||
char buff[BUFFSZ];
|
||||
int N;
|
||||
int N = 0;
|
||||
|
||||
int I = 0;
|
||||
for(I=0;I<BUFFSZ;I++) buff[I] = '\0'; //this shuts valgrind up about uniitialized values
|
||||
|
||||
if(fp!=NULL && s!=NULL)
|
||||
{
|
||||
if(!feof(fp))
|
||||
|
||||
@ -429,6 +429,12 @@ namespace ams
|
||||
|
||||
fp = fopen("./ref/0p375_hexbolt.scad","r");
|
||||
fp2 = fopen("./ref/testrewrite.scad","w+");
|
||||
|
||||
if(fp==NULL || fp2==NULL)
|
||||
{
|
||||
printf("amsstring4_test_freadwrite: could not open test files, make sure you're executing this from the project root.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
I = 0;
|
||||
while(!feof(fp))
|
||||
|
||||
@ -20,7 +20,7 @@ int main(int argc, char* argv[])
|
||||
amsstring4_test_strip();
|
||||
amsstring4_test_freadwrite();
|
||||
|
||||
amsstring4_test_concatenation_operators();
|
||||
amsstring4_test_concatenation_operators(); //segfault on Debian11?
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user