diff options
author | amy <[email protected]> | 2023-05-19 12:37:18 +0000 |
---|---|---|
committer | amy <[email protected]> | 2023-05-19 12:37:18 +0000 |
commit | eb9170b07a0d28dc0b89a5b20625dd7b145a1eda (patch) | |
tree | 02882619a69d9560aa143815435c30149588219e /src/util.c | |
parent | 303f6c61f9d0bbf1b4f962301c45f9439b5230c3 (diff) |
nyaaa~
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -15,7 +15,7 @@ typedef struct { unsigned long size; } alloc; alloc* allocations = NULL; -double binomial(int n, int k){ +inline double binomial(int n, int k){ if(n==k) return 1.0; double v = 1.0; @@ -24,10 +24,10 @@ double binomial(int n, int k){ } return v; } -void* mmalloc(size_t X,char*file,int line,char*func){ +inline void* mmalloc(size_t X,char*file,int line,char*func){ void* mal = (malloc)(X); if(mal==NULL) - abort(); + err_m("malloc error",exit,file,line); //abort(); #ifdef memory_trace if(allocations==NULL){ allocations=(malloc)(sizeof(*allocations)*2); @@ -48,9 +48,9 @@ void* mmalloc(size_t X,char*file,int line,char*func){ } -void ffree(void* X,char*file,int line,char*func){ +inline void ffree(void* X,char*file,int line,char*func){ if(X==NULL){ - warn("tried to free a null pointer"); + warn_m("tried to free a null pointer",file,line); return; } #ifdef memory_trace @@ -125,11 +125,11 @@ unsigned int_len(const unsigned n) { return 1 + int_len(n / 10); }//https://stackoverflow.com/a/3068415 char* force_ca_length(char*inp,int len){ - char* nya = malloc(sizeof(*nya)*(len+1)); + char* nya = malloc(sizeof(*nya)*(len+2)); int skip = 0; for(int i = 0;; i++){ nya[i] = ' '; - if((inp[i]=='\0'||skip)&&i>=len) + if((skip||inp[i]=='\0')&&i>=len) break; if(inp[i]=='\0') skip=1; |