Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Cast shift operand to uint to comply with Go's type requirements #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

takaeda
Copy link

@takaeda takaeda commented Aug 2, 2024

Description

Problem

The current implementation of the alaw.go and ulaw.go files uses int16 type for shift operations, which causes compilation errors in newer versions of Go. The error messages are as follows:

../../go/src/github.com/zaf/g711/alaw.go:95:18: invalid operation: compressedByte >>= seg - 1 (shift count type int16, must be unsigned integer)
../../go/src/github.com/zaf/g711/ulaw.go:102:24: invalid operation: frame >> seg (shift count type int16, must be unsigned integer)

Solution

This pull request addresses the issue by casting the shift operands to uint, ensuring compliance with Go's requirement for unsigned integer types in shift operations.

Changes

  1. In alaw.go:

    // Before: compressedByte >>= seg - 1
    // After:
    compressedByte >>= uint(seg - 1)
  2. In ulaw.go:

    // Before: frame >> seg
    // After:
    frame >> uint(seg)

Impact

These changes resolve the compilation errors without altering the logic of the code. It ensures compatibility with current and future versions of Go that enforce stricter type checking for shift operations.

Testing

The modifications have been tested locally, and the package now compiles successfully without any errors related to shift operations.

Additional Notes

This fix is necessary for users trying to use this package with recent Go versions. It maintains the original functionality while adhering to Go's language specifications.


I appreciate your time in reviewing this pull request. Please let me know if you need any further information or if you'd like me to make any additional changes.

@zaf
Copy link
Owner

zaf commented Aug 29, 2024

Thank you for the detailed report. Can you please let me know of the Go version and platform that experiences this error? It seems to compile fine with 1.23 so I guess your changes are needed for some future version (1.24?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants