Finding integration bounds for density of sum of two independent random variables 
Let $X, Y$ be independent random variables, both uniformly distributed over the interval $(0,1)$. That is, $$f_{X}(a)=f_{Y}(a) =  \begin{cases} 1 & \text{if $0 < a <
 1$} 
\\ 0 & \text{otherwise} \end{cases}$$
  Find $f_{X+Y}(a)$.

In my probability course, the solution to this problem was given as follows, but figuring out the integrals was very much "by inspection", and for this one, particular problem.
$$
f_{X+Y}(a) = 
\begin{cases} 
\int_{0}^{a} dy = a & \text{if $0 < a < 1$} 
\\\int_{a-1}^{1} dy = 2 - a & \text{if $1 < a < 2$} 
\end{cases}$$
It's not so apparent to me how we know these are the correct integration bounds in these two cases. I want a general, straightforward way to figure out exactly which integrals need to be computed for probability problems of this kind. So I read this answer by André Nicolas, which it finally made it clear to me how to start finding $P(X+Y \le a)$:

Another way: (Sketch) We can go after the cdf $F_Z(z)$ of $Z$, and then differentiate. So we need to find $\Pr(Z\le z)$.
For fixed $z$, draw the line with equation $x+y=z$. Draw the
  square $S$ with corners $(0,0)$, $(1,0)$, $(1,1)$, and $(0,1)$. 
Then $\Pr(Z\le z)$ is the area of the part $S$ that is "below" the
  line $x+y=z$. That area can be calculated using basic geometry. There
  is a switch in basic shape at $z=1$.  

Then by drawing a figure with a square with vertices $(0,0), (0, 1), (1,0), (1,1)$, I come up with the following two integrals:
$$ 
\small
P(X+Y \le a) = \int_{0}^{1} \left( \int_{0}^{a-y} f(x) \ \mathrm{d} x \right) f(y) \ \mathrm{d}y = \int_{0}^{1} \left( a-y \right )1  \ \mathrm{d}y = a - \frac{1}{2}   \ \ \ \ \  \text{if $0 < a < 1$}  
$$
$$
  \small 
P(X+Y \le a) = \int_{0}^{1} \left( \int_{1-y}^{a-y} f(x) \ \mathrm{d} x \right) f(y) \ \mathrm{d}y = \int_{0}^{1}  \left( (a-y) - (1 - y) \right )1  \ \mathrm{d}y = \int_{0}^{1} (a - 1)  \ \mathrm{d}y  \ \ \  \text{if $1 < a < 2$}  
$$
It appears that I have made a mistake somewhere, since $\frac{d}{\mathrm{d}\ a}\left(F_{X+Y}(a)  \right) =\frac{d}{\mathrm{d}\ a}\left( P(X+Y\le a) \right) = f_{X+Y}(a)$ in neither case gives me the correct answer for $f_{X+Y}(a)$.
Please help me see my mistake; what am I missing? 
 A: This problem is best solved by drawing diagram by plotting the line $x+y=z$ in 'x-y' plane and measuring the area under the line over the rectangle enclosed by $(0,0), (0,1), (1,0)$ and $(1,1)$ [covering $(x+y\leqslant z)$]. This is my recommendation. Alternatively, you may want to use method of convolution while calculating cdf of the sum X+Y exactly the way you have attempted (for details see this).
Looking at your approach I can see the issue in the range of y used in the integral when you try to find $P(X+Y\le a)$ for $0<a<1$. Unfortunately you can't write: $\int_{0}^{1} \left( \int_{0}^{a-y} f(x) \ \mathrm{d} x \right) f(y) \ \mathrm{d}y = \int_{0}^{1} \left( a-y \right )1  \ \mathrm{d}y$, since, when $0<X<a-y$, $0<a-Y<1$; thus, $a-1<Y<a$; but since we are evaluating the cdf for $0\le a\le1$, the range of Y eventually reduces to $0<Y<a$.
Similar sort of issue appears for the case $1\le a\le2$. Basically we just need to be a bit careful about the ranges so that the bounds used are valid ones.
