aspose file tools
The moose likes Java in General and the fly likes interview Question - buffer overflow Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "interview Question - buffer overflow" Watch "interview Question - buffer overflow" New topic
Forums: java Jobs
Author

interview Question - buffer overflow

Tiya Khambadkone
Ranch Hand

Joined: Sep 15, 2011
Posts: 40
given a buffer A (size unknown , length known) attach another buffer B to the end of buffer A such that A does not over-flow. both buffer's size is unknown and length is known.

How will you achieve this ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32620
    
    4
Is that actually a Java question? It sounds like the sort of thing which you do with malloc and clear, in C.
If it is an interview question, what did you say?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 4734
    
    7

Tiya Khambadkone wrote:given a buffer A (size unknown , length known) attach another buffer B to the end of buffer A such that A does not over-flow. both buffer's size is unknown and length is known.
How will you achieve this ?

Simple answer: Without
(a) some way of determining the "end" of a buffer.
AND
(b) some way of knowing the capacity of buffer A (note: NOT necessarily the same as its length).
you can't.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Wouldn't this do the trick?

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16683
    
  19

Dennis Deems wrote:Wouldn't this do the trick?




Sure, but it is also *not* needed. Remember that a string buffer will ensure its capacity automatically. You just append the other item, and it is done for you.


I am agreeing that this is likely a C question -- in that it is asking how to ensure capacity with a malloc'ed buffer.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: interview Question - buffer overflow
 
Similar Threads
Tomcat Startup problem
Accessing Java HttpServer from PHP;
UBB bug
Content Length header
Response from RS232 device is not complete?