improve // d: add a / next a str if missing // i: str path // o: mstr with an added / //…
- User
improve // d: add a / next a str if missing // i: str path // o: mstr with an added / // o: str "" if path 0 sized // o: FIXME maybe NULL in case of allocation failure // c: function does copy path so as to keep it safe // c: so user should realloc(0) result memory sbyte *append_slash(const sbyte *path) {
if (path == NULL || path[0] == '\0') { return NULL; } size_t src_strsize = strlen(path); if (src_strsize<=0){ return ret; } sbyte *ret=NULL; // str len abc\0 ==3 // yet as addresses: // sbyte 0=a 1=b 2=c 3=\0 // address 'len' is out o str range - str range being 0 > len-1 // address 'len' is supposed being \0 termination // address 'len-1' would be content, / or something else if (strcmp(&path[src_strsize-1],"/")==0){ ret=calloc(src_strsize+1,sizeof(sbyte)); if(ret==NULL){ return(NULL); } //memset(ret, 0, sizeof(sbyte)*(src_strsize)+1 ); // copy path so as to keep it safe memcpy(ret, &path[0], src_strsize); } else { ret=calloc(src_strsize+1+1,sizeof(sbyte)); if(ret==NULL){ return(NULL); } //memset(ret, 0, sizeof(sbyte)*(src_strsize)+1+1 ); memcpy(ret, &path[0], src_strsize); //sprintf(ret,"%s/",path); ret[src_strsize] = '/'; ret[src_strsize+1] = '\0';// \0 termination } return ret;}
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.