** translate a relative initial string position ** (negative means back from end): clip result to [1, inf). ** The length of any string in Lua must fit in a lua_Integer, ** so there are no overflows in the casts. ** The inverted comparison avoids a possible overflow ** computing '-pos'. */
| 69 | ** computing '-pos'. |
| 70 | */ |
| 71 | static size_t posrelatI (lua_Integer pos, size_t len) { |
| 72 | if (pos > 0) |
| 73 | return (size_t)pos; |
| 74 | else if (pos == 0) |
| 75 | return 1; |
| 76 | else if (pos < -(lua_Integer)len) /* inverted comparison */ |
| 77 | return 1; /* clip to 1 */ |
| 78 | else return len + (size_t)pos + 1; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | /* |
no outgoing calls
no test coverage detected