Skip to content

sine_wave likely to generate value too large for "H" array.array #9

@kevinjwalters

Description

@kevinjwalters

When length is even this is likely to try to assign 65536 (depending a little on floating point part of calculation and math functions) to a 16bit unsigned value, i.e. it will overflow it. The multiplier of 2**15 (32768) is too large, value-between-minus1-plus1-at-plus1 * 32768 + 32768 = 65536.

    b = array.array("H", [0] * length)
    for i in range(length):
        b[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 15) + 2 ** 15)

The same code is used in various places. I'd suggest a scan across alll Learn guides and adafruit's whole repo.

Reported/discussed on: https://forums.adafruit.com/viewtopic.php?f=60&t=153174

Is adafruit/circuitpython#1860 or something similar the reason why this has gone unnoticed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy