Hershey Co. (HSY) - Get Report is all treat and no trick as Halloween approaches, but declining gross margins are worrying investors.

The candy giant reported a strong third quarter on Thursday, Oct. 26, despite upheaval in the packaged food and candy industry.

During the quarter ending Oct. 2, Hershey generated sales of $2.03 billion, up 1.5% year over year and ahead of the consensus estimate of $2.01 billion, according to FactSet. Earnings of $1.33 per share also exceeded analysts' expectations of $1.29 per share.

"Snacking continues to outpace the market in a rapidly changing environment," said Hershey CEO Michele Buck in a statement. "The investments we're making in our power chocolate brands - Reese's, Hershey's, Kit Kat and Kisses - are resonating with consumers in the marketplace."

While Hershey lowered prices 0.3%, its 1.6% North American volume growth "is much better than other non-snack companies are seeing in the center of the store," wrote Bernstein analyst Alexia Howard. "It seems that the overall indulgent snack category is continuing to hold up reasonably well, and Hershey is holding its own based on recent innovations in its core chocolate brands." Falling gross margins should get a boost from declining cocoa prices, she noted.

Hershey also touted retail-ready packaging improvements, which will begin to roll out next quarter, and e-commerce sales up 40%. The initiatives "should result in improved shelf presence and visibility" despite the immediate hit to gross margins, Buck said on a call with analysts.

Halloween retail sales are expected to increase 4.5% this year, according to Deloitte, and the National Retail Federation expects candy sales of $2.7 billion.

Full-year earnings guidance at the high end of $4.72 to $4.81 per share. Hershey's board also approved a new $100 million buyback program. That buyback will commence after Hershey completes a prior share buyback program, which has $100 million remaining.

Buck, the former COO, became CEO in March. Her appointment in December came months after Hershey rejected a $23 billion acquisition offer from Mondelez International Inc. (MDLZ) - Get Report . Hershey is a difficult takeover target, because it's controlled by a charitable trust, the Hershey Trust Co., which holds about 80% of the company's voting power.

Hershey and privately held Mars Inc. control 64% of the U.S. chocolate share, according to Euromonitor data. At 14%, Hershey also has the largest non-chocolate U.S. candy share.

"The N. American topline was much better than we expected," wrote Wells Fargo analyst John Baumgartner, adding that he's "increasingly positive on [Hershey's] 'snackfection'" strategy. "We surmise that the market will take the revenue upside and split the difference with the EPS disappointment. We'd expect to see HSY flattish today."

As grocery margins compress further and Millennial snacking habits turn toward healthier options, M&A activity has heightened in the candy category. Nutella maker Ferrero International SA, for instance, acquired private equity-backed Ferrara Candy Co. last week for undisclosed terms. Ferrara, which owns the Trolli, Lemonheads and Red Hots brands, generated 2016 revenue of $859 million, according to Moody's.

Food giant Nestlé SA (NSRGY) - Get Report , meanwhile, plans to sell its U.S. confectionary business, which generated 2016 sales of 900 million Swiss francs ($908.5 million), before the end of the year. The brands for sale include Crunch, Butterfinger and Baby Ruth, but not Kit Kat, Nestlé's most valuable brand, which Hershey licenses in the United States.

Both Hershey and Ferrara are reportedly bidding for the unit.

Hershey shares fell 3.2% to $105.16 in Thursday morning trading. Year to date, Hershey shares are up 5%, trailing the S&P's 14.2% rise.

More of What's Trending on TheStreet: