If I were you, I would not copy even truly "trivial" amounts of code.
Here's my thing: Oracle v Google was a fight that ended up being about two specific things, one was whether API-declaring interface code could be a subject of copyright law. Once it was found that interfaces could be copyrighted the lawsuit turned its focus to thing two: whether Google's use was fair use.
The part of copyright law, as written, that protects your ability to copy a 9-line RangeCheck function, is NOT, emphatically NOT fair use. It is convergence, the least-known of all the copyright principles.
Convergence says that if many people not coordinating could be expected to all land on the same results, then logically the activity must not be creative expression and the result must not be possible to copyright. This is why nobody owns math equations like e=mc^2. It's not that no creativity was required to derive the equation, it's that anyone working at it would end up with a result of that form.
In programming this would protect you when you do something like write a parser for a programming language, or implement a common helper function. Anything where you may, through now fault of your own, do work that creates a result similar to work that someone else has already done.
I don't know that any significant court case has ever even had arguments based on convergence even though it's the most practical shield most of us have most of the time.
"for(int j=0; j<ARRAY_SIZE(a); j++) total += a[j];" - you could copy paste this and more out of leaked Windows source code and it still wouldn't be a copyright violation. But beware that a sum of a large number of trivialities can be not trivial.
All completely unsettled law at this point. And, as a general guiding principle, you do NOT want to be one of the people who pays millions in legal fees and court costs to find out, whether you are right or wrong.