From 2bf21d6516ed44567e9cf842b25fc30a3affc03f Mon Sep 17 00:00:00 2001 From: epoch Date: Sun, 9 Feb 2014 06:27:44 -0600 Subject: upgraded format_magic() to hopefully be more compatible and less voodoo-y. --- segfault | Bin 26258 -> 26200 bytes segfault.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- testing.c | 65 ------------------------------------------------------------- 3 files changed, 62 insertions(+), 66 deletions(-) delete mode 100644 testing.c diff --git a/segfault b/segfault index 4a18bb0..a94eb6d 100755 Binary files a/segfault and b/segfault differ diff --git a/segfault.c b/segfault.c index f3721b4..b98973c 100644 --- a/segfault.c +++ b/segfault.c @@ -111,6 +111,67 @@ struct tail { void message_handler(int fd,char *from,char *nick,char *msg,int redones); void c_untail(int fd,char *from, char *file); +char *format_magic(int fd,char *from,char *nick,char *orig_fmt,char *arg) { + int i,j; + int sz=0,c=1; + char *output; + char *fmt=strdup(orig_fmt); + char **args,**notargs; + for(i=0;fmt[i];i++) { + if(fmt[i] == '%') { + i++; + switch(fmt[i]) { + case 'u': + case 'f': + case 's': + c++; + } + } + } + args=malloc((sizeof(char *)) * (c + 1)); + notargs=malloc((sizeof(char *)) * (c + 2)); + c=0; + for(j=0,i=0;fmt[i];i++) { + if(fmt[i] == '%') { + i++; + switch(fmt[i]) { + case 'u': + args[c]=nick; + break; + case 'f': + args[c]=from; + break; + case 's': + args[c]=arg; + break; + } + switch(fmt[i]) { + case 'u': + case 'f': + case 's': + fmt[i-1]=0; + notargs[c]=strdup(fmt+j); + sz+=strlen(args[c]); + sz+=strlen(notargs[c]); + c++; + i++; + j=i; + break; + } + } + } + notargs[c]=strdup(fmt+j); + sz+=strlen(notargs[c]); + output=malloc(sz+1); + for(i=0;i - -char *format_magic(char *from,char *nick,char *fmt,char *arg); - -int main(int argc,char *argv[]) { - char *o=format_magic("#default","epoch",argv[1],argv[2]); - printf("%s\n",o); - return 0; -} - -char *format_magic(char *from,char *nick,char *fmt,char *arg) { - int i; - int j; - int c=1; - for(i=0;fmt[i];i++) { - if(fmt[i] == '%') { - i++; - switch(fmt[i]) { - case 0: - printf("error! last character is a '%'!!!\n"); - exit(1); - case 'u': - case 'f': - case 's': - c++; - } - } - } - char **args=malloc((sizeof(char *)) * (c + 1)); - c=0; - for(i=0;fmt[i];i++) { - if(fmt[i] == '%') { - i++; - switch(fmt[i]) { - case 0: - printf("error! last character is a '%'!!!\n"); - exit(1); - case 'u': - args[c]=nick; - fmt[i]='s'; - c++; - break; - case 'f': - args[c]=from; - fmt[i]='s'; - c++; - break; - case 's': - args[c]=arg; - c++; - break; - } - } - } -// args[c]=0; -// for(i=0;i