Git Product home page Git Product logo

Comments (6)

johnsonjh avatar johnsonjh commented on June 12, 2024 1

I'll revise it shortly.

from supdup.

johnsonjh avatar johnsonjh commented on June 12, 2024

Updated to just use the portable version everywhere.

Seems that Travis doesn't have libbsd, so it's likely others won't either.

from supdup.

ams avatar ams commented on June 12, 2024

I don't follow. There is no benefit here to use strlcpy? No error checking is done on the return value. You also changed strncpy calls to strlcpy calls?

from supdup.

larsbrinkhoff avatar larsbrinkhoff commented on June 12, 2024

Certainly doing buffer overflow checks throughout would be a welcome improvement.

from supdup.

johnsonjh avatar johnsonjh commented on June 12, 2024

Yes, in this particular case there isn't any real change.

However, this does reduce the overall complexity of the code by not requiring operating system specific #ifdef's or using external libraries and eases future maintenance by having a single platform agnostic way to do things.

Also, the replacement of strncpy was:

#ifdef __OpenBSD__
	strlcpy(myloc, argv[1], sizeof(myloc));
#else
	strncpy(myloc, argv[1], sizeof(myloc));
#endif

Using strlcpy on BSD and strncpy and friends on other platforms adds, at a bare minimum, three lines (conditional compilation, no less) for each and every instance of use (not including the duplicated statement itself), while the portable strlcpy implementation is just seven statements in total (not counting variable declarations, comments, and formatting). It has been stable for nearly 25 years and is unlikely to change in the future. Not to mention, with strncpy, there is the need to manually handle NULL-termination in cases of truncation, etc.

Having a single function to use on all platforms that uses the same code, works exactly the same everywhere, and also reduces the total lines of code needed while removing the need for conditional compilation is really the benefit.

(IMO, to this end, the __OpenBSD__ #ifdef's should be removed all together if the change is accepted - I did not do so in this commit to keep the patch to the minimum viable change.)

from supdup.

ams avatar ams commented on June 12, 2024

Then I think I'd lke to see the change addresses the entirety of the problem, as it is now I see little benefit. You say that it reduces a few #if's -- but the added code for strlcpy(3) has a size and maintenance cost as well, over 25 years much can happen... :-)

from supdup.

Related Issues (16)

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.