File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interview Question - buffer overflow

 
Tiya Khambadkone
Ranch Hand
Posts: 67
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9477
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
dennis deems
Ranch Hand
Posts: 808
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't this do the trick?

 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic