Giter Site home page Giter Site logo

Comments (2)

kr avatar kr commented on August 24, 2024 3

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.

from pretty.

cocolato avatar cocolato commented on August 24, 2024

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.

from pretty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.