| 2277 | } |
| 2278 | |
| 2279 | static cbm_git_bytes_t gfb_frame(CBMArena *arena,const char *oid,const void *body,size_t length, |
| 2280 | bool payload) { |
| 2281 | char header[128];int n=snprintf(header,sizeof(header),"%s blob %zu\n",oid,length); |
| 2282 | if(n<=0 || (size_t)n>=sizeof(header) || length>SIZE_MAX-(size_t)n-1) |
| 2283 | return (cbm_git_bytes_t){NULL,0}; |
| 2284 | size_t total=(size_t)n+(payload?length+1:0); |
| 2285 | unsigned char *bytes=cbm_arena_alloc(arena,total); |
| 2286 | if(!bytes)return (cbm_git_bytes_t){NULL,0}; |
| 2287 | memcpy(bytes,header,(size_t)n); |
| 2288 | if(payload) { |
| 2289 | if(length)memcpy(bytes+n,body,length); |
| 2290 | bytes[total-1]='\n'; |
| 2291 | } |
| 2292 | return (cbm_git_bytes_t){bytes,total}; |
| 2293 | } |
| 2294 | |
| 2295 | static cbm_git_bytes_t gfb_concat(CBMArena *arena,cbm_git_bytes_t a,cbm_git_bytes_t b) { |
| 2296 | if(a.length>SIZE_MAX-b.length)return (cbm_git_bytes_t){NULL,0}; |
no test coverage detected