| 485 | #define addstr(a,b,l) ( memcpy(a,b,(l) * sizeof(char)), a += (l) ) |
| 486 | |
| 487 | void luaO_chunkid (char *out, const char *source, size_t bufflen) { |
| 488 | size_t l = strlen(source); |
| 489 | if (*source == '=') { /* 'literal' source */ |
| 490 | if (l <= bufflen) /* small enough? */ |
| 491 | memcpy(out, source + 1, l * sizeof(char)); |
| 492 | else { /* truncate it */ |
| 493 | addstr(out, source + 1, bufflen - 1); |
| 494 | *out = '\0'; |
| 495 | } |
| 496 | } |
| 497 | else if (*source == '@') { /* file name */ |
| 498 | if (l <= bufflen) /* small enough? */ |
| 499 | memcpy(out, source + 1, l * sizeof(char)); |
| 500 | else { /* add '...' before rest of name */ |
| 501 | addstr(out, RETS, LL(RETS)); |
| 502 | bufflen -= LL(RETS); |
| 503 | memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char)); |
| 504 | } |
| 505 | } |
| 506 | else { /* string; format as [string "source"] */ |
| 507 | const char *nl = strchr(source, '\n'); /* find first new line (if any) */ |
| 508 | addstr(out, PRE, LL(PRE)); /* add prefix */ |
| 509 | bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */ |
| 510 | if (l < bufflen && nl == NULL) { /* small one-line source? */ |
| 511 | addstr(out, source, l); /* keep it */ |
| 512 | } |
| 513 | else { |
| 514 | if (nl != NULL) l = nl - source; /* stop at first newline */ |
| 515 | if (l > bufflen) l = bufflen; |
| 516 | addstr(out, source, l); |
| 517 | addstr(out, RETS, LL(RETS)); |
| 518 | } |
| 519 | memcpy(out, POS, (LL(POS) + 1) * sizeof(char)); |
| 520 | } |
| 521 | } |
| 522 |
no outgoing calls
no test coverage detected