Is it considered plagiarism on Stack Overflow to take material from another answer on the same question and reuse it with modifications?
Details
I recently answered a question which had been partially answered by another user. It seemed to me this answer had started well and then lost the thread of the task at hand. There was code that would not compile and the answer did not answer the actual question.
I added a comment to the answer saying it would not compile and did not answer the question.
The answerer replied (paraphrased) they had done enough to get the user in the right direction.
So I copied some of the code from this answer, fixed it so it solved the problem in a way that the OP would understand and posted it as a new answer.
I was then accused of plagiarism
At this point I started getting downvotes. I can only assume I was getting the downvotes because of perceived bad behavior -- since my code worked while the other answer did not even compile.
So my question is this:
Is it considered plagiarism on Stack Overflow to take material from another answer on the same question and re-use it with modifications?
Do we need to point to material which is on the same page? Did I overstep some bound here?
I don't want to be the high-rep bully here, this is a new user trying to add to the site and I feel I gave him a chance to answer the question first. At the same time I don't like being accused of something I didn't do according to the standard of this site.
Question for reference: A better way to fill a two-dimensional array with date and zodiac sign
Clarification - I'm specifically asking about not having attribution in the text of the answer since I was originally lazy and did not include it. Since it was on the same page as the answer I was enhancing, it seems clear to me (maybe only as an experienced user who knows SO) where the original code came from. This is what my question is concerning.