repo: uritools action: commit revision: path_from: revision_from: 02597fd74545be69483e6ebd8370201480875fc7: path_to: revision_to:
commit 02597fd74545be69483e6ebd8370201480875fc7 Author: epochDate: Mon Aug 14 23:02:38 2023 -0500 we calculate the amount of space we will likely need when converting a URI to a line diff --git a/uri.h b/uri.h
--- a/uri.h
+++ b/uri.h
@@ -119,8 +119,13 @@ unsigned int uricmp(struct uri *a,struct uri *b) {
}
char *linefromuri(struct uri *u) {
- char *line=malloc(2048);//fuck if I know
- // maybe loop over all the input parts and add up the lengths then add a bit of extra for separators
+ int len=16; // length of all delimiters we might get... :// : @ [ ] : / ? # (and 5 more for good luck)
+ char *line;
+ for(i=0;i<8;i++) {
+ if(u->A[i]) len+=strlen(u->A[i]);
+ }
+ line=malloc(len);// I kind of don't like this using malloc. :/
+ if(!line) return 0;
strcpy(line,"");
if(u->scheme) {
strcat(line,u->scheme);
-----END OF PAGE-----