| 855 | } |
| 856 | |
| 857 | static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { |
| 858 | const char *p = strfrmt; |
| 859 | while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ |
| 860 | if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char)) |
| 861 | luaL_error(L, "invalid format (repeated flags)"); |
| 862 | if (isdigit(uchar(*p))) p++; /* skip width */ |
| 863 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
| 864 | if (*p == '.') { |
| 865 | p++; |
| 866 | if (isdigit(uchar(*p))) p++; /* skip precision */ |
| 867 | if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ |
| 868 | } |
| 869 | if (isdigit(uchar(*p))) |
| 870 | luaL_error(L, "invalid format (width or precision too long)"); |
| 871 | *(form++) = '%'; |
| 872 | memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char)); |
| 873 | form += p - strfrmt + 1; |
| 874 | *form = '\0'; |
| 875 | return p; |
| 876 | } |
| 877 | |
| 878 | |
| 879 | /* |
no test coverage detected