Questions tagged [off-by-one]

A class of errors commonly made by programmers characterized by accessing arrays at an index, whose value is greater or lesser than the intended value by 1

An off-by-one error (OBOE) is a logic error involving the discrete equivalent of a boundary condition. It often occurs in computer programming when an iterative loop iterates one time too many or too few. Usually this problem arises when a programmer fails to take into account that a sequence starts at zero rather than one (as with array indices in many languages), or makes mistakes such as using "is less than or equal to" where "is less than" should have been used in a comparison. This can also occur in a mathematical context.

[source]

51 questions
0
votes
1 answer

Inventory program, possible boundary value issue?

The below program seems to work well in most situations, but if I add a record for the last inventory position (record 10), it causes issues. Specifically, if I add record 10 then try and delete it, it still shows in the inventory after I call…
0
votes
1 answer

C Program Incorrect Output

I am currently writing a program that is supposed to receive input from a text file and output statistics about the text such as the number of letters, size of words and how often they occur, and how many times each word occurs. However, every time…
Noah210012
  • 89
  • 9
0
votes
2 answers

I seem to have an off-by-one error in the ListView.Row("Name", "Value") method of TestStack White

All I wish to do is right-click on the row where Name="2". So I use: ListView list = output.Get(SearchCriteria.ByAutomationId("selectorUser1")); if (list.Items.Contains(keyName)) { ListViewRow lvr = list.Row("Name", keyName); …
user741944
  • 41
  • 2
0
votes
0 answers

iText pdfcopy close off by one error

I see this error a lot in an application with a lot of traffic when dealing with a PDF merge request. java.lang.RuntimeException: The page 3 was requested but the document has only 2 pages. at …
user63684
  • 101
  • 1
0
votes
1 answer

How can I put a null value for char** str

How can I put a null value for char** str because im having and Error of "Dereference of out of bound pointer: 1 bytes(1element) past end of array im using C language" while(part) { res = (char**)realloc(res, (i + 1) * sizeof(char*)); …
0
votes
1 answer

Loop doesn't behave the way I expect

The code I have written compiles but does not produce the output I was expecting. It ends before I have put in all of my input data and doesn't give me the correct output. Any idea where the mistake(s) is? Here's main program: public static void…
0
votes
1 answer

Why does my VB.NET array have extra values?

I declare my array Dim A(N) As Integer When I loop from 1 To N or 0 To N-1 there's an extra value at one end or the other. What's going on? (Intended to be a canonical question/answer.)
Mark Hurd
  • 10,665
  • 10
  • 68
  • 101
0
votes
2 answers

Unsuccessful if condition

My function is supposed to have a successful start sequence when ever it encounters 0 0 0 0 1 1 0 but when i input these numbers the number of successful start sequence does not change However that doesn't stop it from compiling and I can't spot…
0
votes
1 answer

strncat off by one error - K&R C exercise 5-5

My version of strncat is copying one too many chars into the destination and I cannot figure out why. #include #define MAX_CHARS 20 void nconcatenate(char *start, char *end, int n) { if(sizeof start + n > MAX_CHARS) return; …
CS Student
  • 1,613
  • 6
  • 24
  • 40
0
votes
1 answer

Preventing off-by-one errors with CRT secure string functions

As of Visual Studio 2005, the CRT has replaced most string functions with secure versions which add a size argument to indicate the limits of the destination buffer(s). This is fine, but it’s not clear how it should be used. Does it include the…
Synetech
  • 9,643
  • 9
  • 64
  • 96
0
votes
0 answers

Quicksort won't sort more than 50 elements

Here's how I generate the numbers to be sorted. vector list; for (i=0;i<50;i++) list.push_back(rand() %1000); Here is my call in main quickSort(list , 0, (list.size() -1 )); here's the quicksort function int pivot = left; int temp =…
Donovan King
  • 855
  • 1
  • 6
  • 18
0
votes
2 answers

Off by one error for char-ing string

This method is supposed to take in a string and output the string as chars however it should be double the size. Example: the string is "PaRty" return should be 'P', 'P', 'a', 'a', 'R', 'R', 't', 't', 'Y', 'Y' For my code, when I run the test it…
0
votes
4 answers

Nested For loop incrementing after termination

I've got 2 for loops, one nested inside of another. They loop through a 2D array of buttons to get the source of each button thats been clicked using the action listener. When the button is found I pass the position/array indexs of the button to an…
CS Student
  • 1,613
  • 6
  • 24
  • 40
0
votes
1 answer

Small Malfunction, no Exception, when Application.ScreenUpdating = False is used VB.NET

I ran into something I've not seen before, Application.ScreenUpdating = False, causing a sub to slightly misbehave. It doesn't throw an error, but it causes an off by one error in the result when turned on. Try …
Atl LED
  • 656
  • 2
  • 8
  • 31
0
votes
1 answer

How to be definite about the number of whitespace fmt.Fscanf consumes?

I am trying to implement a PPM decoder in Go. PPM is an image format that consists of a plaintext header and then some binary image data. The header looks like this (from the spec): Each PPM image consists of the following: A "magic number" for…
fuz
  • 88,405
  • 25
  • 200
  • 352