There is no problem. Since you patch in memory, all data of the lib are basically glue together, that's why you can't go above the original size, because you would overlap on next string for example. When you replace abcd -> ab, you did no change the original boundaries. It's like having [ab__]. So what it matters is the original string size, ab -> abcd should be fine.