repo: uritools
action: commit
revision: 
path_from: 
revision_from: 02597fd74545be69483e6ebd8370201480875fc7:
path_to: 
revision_to: 
git.thebackupbox.net
uritools
git clone git://git.thebackupbox.net/uritools
commit 02597fd74545be69483e6ebd8370201480875fc7
Author: epoch 
Date:   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
index b41e3ef174c942823404ac2b34998764bb0842af..
index ..a33a92694356abd8f72d0c5d965266dbd583f808 100644
--- 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-----