You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reference looping causes recursion to fail to terminate, resulting in stack overflow #72
Infinite recursion can also be triggered by self-referential data structures in "fmt" pkg, such as a slice that contains itself as an element, if that type has a String method. Such pathologies are rare, however, and the package does not protect against them.
It's true that fmt doesn't try to protect against cyclic data structures, but I think it's reasonable for pretty to be more defensive and to do something about it.
Maybe we should have a limit on depth of traversal.
If so, I guess there should also be a way for the caller to adjust the limit in cases where that's necessary. For example, maybe the default limit is 1000, and most callers never hit it. But if you have a cycle, it will prevent a crash. If you have a deeply nested non-cyclic structure and you want to print all of it, you can increase the limit. Or if you're in a resource-constrained environment, you can lower the limit.
But hopefully almost everyone would never have to adjust the limit or even know it exists.
Reacted by Hai Zhu, David Ohlemacher and Hans van den Bogert
Activity
cocolato commentedon Apr 27, 2021
Infinite recursion can also be triggered by self-referential data structures in "fmt" pkg, such as a slice that contains itself as an element, if that type has a String method. Such pathologies are rare, however, and the package does not protect against them.
kr commentedon Apr 27, 2021
It's true that fmt doesn't try to protect against cyclic data structures, but I think it's reasonable for pretty to be more defensive and to do something about it.
Maybe we should have a limit on depth of traversal.
If so, I guess there should also be a way for the caller to adjust the limit in cases where that's necessary. For example, maybe the default limit is 1000, and most callers never hit it. But if you have a cycle, it will prevent a crash. If you have a deeply nested non-cyclic structure and you want to print all of it, you can increase the limit. Or if you're in a resource-constrained environment, you can lower the limit.
But hopefully almost everyone would never have to adjust the limit or even know it exists.
Use pretty from upstream package