answersLogoWhite

0

The problem with buffers is that you need to keep track of the amount of memory physically allocated to the buffer. This means a buffer has at least two variables: a reference to the allocation and its size. If the buffer size is constant it is obviously easier to keep track of its length but if it is variable you must ensure the size variable is kept in sync with the actual buffer length. The easiest way to keep track of buffer lengths is to store the buffer and its length in a structure:

struct data {

char * buffer;

int length;

};

You still have to ensure the length is kept in sync with the buffer, but now the two can be treated as being a single entity, making it much easier to pass buffers into and out of functions.

However, a better approach is to use object-oriented programming to encapsulate the buffer and its length, thus hiding the details of the representation:

std::vector<char> buffer;

You no longer have to keep track of the length because that is encapsulated within the vector. Every time you push/pop values, the size is incremented or decremented accordingly. All memory management is also handled by the vector, so new memory is allocated as and when required, and the size is adjusted accordingly. All you have to do is rewrite your functions to make use of a vector rather than a buffer.

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

What is the Morris finger worm?

Buffer overflow errors


What is the reliable command buffer overflow in modern warfare 3 and how do i fix it?

It happens to pc and ps3 ppm as far as I know. It happened to me while playing spec ops.


How do you fix buffer overflow with McAfee?

Only issue with the mcafee antivirus itself. Just reinstall the antivirus to resolve the issue.


What is the meaning of stack-based buffer overflow?

A buffer overflow occurs when you put more stuff into it than it can hold. For a stack, it means you put or pushed onto the stack more information than the size of the stack.If I have a stack that can hold 10 entries, then putting 11 in the stack will overflow it.


Does the AMD FX-55 CPU have NX buffer overflow protection?

Yes.


Which of the following can be used for protection against buffer overflow attacks?

Input validation


What can trigger a buffer overflow?

A buffer overflow occurs when a program attempts to write data to a buffer, but exceeds the boundaries of the buffer, similar to Java's "Array Out of Bounds Exception." This could happen with poorly written code that fails to check for the end of the buffer, or it could be exploited maliciously. One exploitative example would be a stack buffer overflow, in which data is copied to a local variable on the stack. But if the data is larger than the local variable can contain, the extra data will "spill over" onto nearby memory. This would allow one to overwrite data that was not intended to be altered.


Stack overflow at line 597?

how to fix stack overflow at line 597


what type of attack that can be avoided by using proper input validation rules?

buffer overflow


How do you fix stack overflow on a computer?

A quick fix for stack overflow problems is to run a registry cleaning program. There are a lot of them out there so just search for Registry Cleaner.


How did binding buffer get its name?

A binding buffer is a substance used in chromatography to fix a specific compound.For example this buffer can be linked to a protein.


How do you avoid data buffer overflow in transport layer?

There is a special bit signaling if the buffer is full. If the buffer is full the bit signals "BUSY" as result transmission stops until the bit changes to "READY" and transmission resumes.

Trending Questions
What is layer pallets? I have to paste some pictures in Windows Movie Maker and it's a project.All my classmates are doing it on nature and cartoons.Can you give me some ideas what can I do but it should be a different one? How a GB of data looks compared to a TB of data? How do you fix an error that says System Fan error press F2 to continue on when all the fans are working fine? How does a magnifying glass ignite a simple common fire on a simple piece of an uninked unlined computer printer paper on a piece of paper on a sunny day? Whats the latest version of Opera Mini? Which one of the following types of computers is not portable iPad Desktop Laptop Desktop with tower? How much is a iPad at cheapest? Will the sims 3 run on a dell inspiron 15z? Can wordart be created using the chart tools format tab? Can realplayer delete things on your computer? Is it true Digital literacy involves having a current knowledge and understanding of computers mobile devices the Internet and related technologies? What to do when laptop does not responds for a particular pen drive? What do the 4 arrows at the bottom of the keyboard do? How do you solve the problem of physical memory dump? What is the largest computer producing country in the world? . When replying to an e- mail who you place in the cc line and who in the bcc line? What increase output without requiring more input? What is the answer on 4 pics 1 word with two men holding card a boy jumping from cliff to cliff and a cliff with water below it with the letters fluzfoumbupy? How much would a hard drive for a Toshiba Tecra 8000 cost?