Major U.S. stock indexes capped a day of listless trading with modest gains Thursday, snapping the market’s two-day losing streak.A late flurry of buying helped lift the indexes, which had spent much of the day moving sideways after an early rally lost momentum. Even so, the market remained on track for its fourth straight weekly loss and its first monthly decline of the year.Gains in technology, health care and consumer discretionary stocks outweighed losses in energy, financials and other sectors. Bond prices rose again, sending yields lower. Oil and gas prices fell sharply.Stocks have been sliding in volatile trading all month as investors come to grips with the potential impact that the escalating trade war between the U.S. and China could have on corporate and economic growth. With one day left of trading in May, the S&P 500 is heading for a monthly loss of about 5.3%.“This 5% or 6% sell-off is really just a resetting of expectations, especially with the sentiment that’s been a gloomy overhang,” said David Lyon, global investment specialist at J.P. Morgan Private Bank.The S&P 500 index rose 5.84 points, or 0.2%, to 2,788.86. The Dow Jones Industrial Average gained 43.47 points, or 0.2%, to 25,169.88.The Nasdaq composite added 20.41 points, or 0.3%, to 7,567.72. The Russell 2000 index of smaller companies fell 4.42 points, or 0.3%, to 1,485.53.Major stock indexes in Europe rose broadly.The U.S. stock market’s slump in May follows a yearlong run for the S&P 500 that culminated in an all-time high on April 30. The benchmark index is still up 11.2% for the year, while the technology-heavy Nasdaq composite is up 14.1%.