sds icon indicating copy to clipboard operation
sds copied to clipboard

A question in sdsIncrLen

Open aronlt opened this issue 11 years ago • 4 comments

In the function sdsIncrLen, I think the statement "assert(sh->free >= 0) " is redundant, because "assert(sh->free >= incr)" makes sure this situation would not happen.

void sdsIncrLen(sds s, int incr) { struct sdshdr sh = (void)(s - sizeof *sh); assert(sh->free >= incr); sh->len += incr; sh->free -= incr; assert(sh->free >= 0); s[sh->len] = '\0'; }

aronlt avatar Nov 14 '14 04:11 aronlt

Yeah, the only thing that could make it be less than 0 would be in a multithreaded programs where two threads are trying to modify the same string at once, but that’d be very broken.

Anyway, @antirez seems to have no intention of maintaining SDS and I emailed him a couple of months ago about it but he never replied, so I’m working on a fork currently located at https://github.com/yabok/sds, though it will be moved to (most likely) https://github.com/yabok/yasl soon.

kyrias avatar Jan 20 '15 09:01 kyrias

See pull request #45 for a fix.

lemzwerg avatar Feb 14 '15 09:02 lemzwerg

@lemzwerg If you look at the repo history and the other PRs and issues open you can see how it's pretty useless to open a PR on this repo.

kyrias avatar Feb 15 '15 23:02 kyrias

Maybe, yes. However, the PRs I produce are just a byproduct and quite easy to generate, so why not. I'm used to normally commit code with associated ChangeLog entries; this essentially means that you have to concisely wrap up your modifications in an atomic way – in most cases this already corresponds to a PR...

lemzwerg avatar Feb 16 '15 05:02 lemzwerg