semaphore: panic on negative weights

The semaphore.Weighted API accepts int64 for weights. If a negative
weight is passed, it mathematically corrupts the internal state tracker
(s.cur) and bypasses the package's existing safety checks.

This adds strict boundary validation to panic immediately if a negative
weight is provided.

Fixes golang/go#80183

Change-Id: I7e74bad404a8b99aef7e3d2189dda43f8ea644c2
GitHub-Last-Rev: ee6289c356f4626ebca52dbe86d856cc713d7be0
GitHub-Pull-Request: golang/sync#31
Reviewed-on: https://go-review.googlesource.com/c/sync/+/796080
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Zain Yousef <zain.19dj@gmail.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2 files changed
tree: 411416b039a1b27eb7fb05ca22942c9072abb9e3
  1. errgroup/
  2. semaphore/
  3. singleflight/
  4. syncmap/
  5. codereview.cfg
  6. CONTRIBUTING.md
  7. go.mod
  8. LICENSE
  9. PATENTS
  10. README.md
README.md

Go Sync

Go Reference

This repository provides Go concurrency primitives in addition to the ones provided by the language and “sync” and “sync/atomic” packages.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/sync.

The main issue tracker for the sync repository is located at https://go.dev/issues. Prefix your issue with “x/sync:” in the subject line, so it is easy to find.