ni / ni/nimi-python

Off-by-one errors in string retrieval unit tests

Open
#526 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-low test
Dominant language
Python
Stars
128
Forks
110
Avg merge
5d 14h
Merged PRs (30d)
10

Description

I don't think this affects production code..

A lot of our unit tests in which we retrieve the string, we don't take into account the extra byte needed for the NULL terminator character.

Take for example NI-FAKE unit test 'test_get_attribute_string'. We use len() to get the size of the string, and this is what the IVI dance returns. However, len() is off by one.

In mock_helper.py.mako, we cancel out the bug with another bug - we also use len() to determine the size to return and thus the size of the buffer our API allocates.

The fix is not as simple as adding 1, because we don't have different code paths for strings and other buffers which do not need the extra element.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the NI-FAKE test_get_attribute_string test and mock_helper.py.mako, then trace how len() determines the returned size and allocated buffer. Compare string retrieval with other buffer paths and verify that the tests cover the NULL terminator without masking a sizing mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.