The Supreme Court has upheld longer prison sentences for people convicted of carrying or using a gun while committing drug trafficking crimes.

The court voted 8-0 Monday to affirm lower court rulings involving defendants who had five years tacked onto their drug trafficking prison terms because they had a gun with them.

Some federal courts had decided that the additional five years could not be added onto related sentences for federal crimes.

Justice Ruth Bader Ginsburg wrote the court's first opinion of the term. Justice Elena Kagan did not take part in the case because of her work on it in the Justice Department before she joined the court.

The consolidated cases are Abbott v. U.S., 09-479, and Gould v. U.S., 09-7073.