@@ -1512,17 +1512,9 @@ void SExpressionWasmBuilder::stringToBinary(const char* input, size_t size, std:
15121512Index SExpressionWasmBuilder::parseMemoryLimits (Element& s, Index i) {
15131513 wasm.memory .initial = getCheckedAddress (s[i++], " excessive memory init" );
15141514 if (i == s.size ()) return i;
1515- while (i < s.size () && s[i]->isStr ()) {
1516- auto * curr = s[i]->c_str ();
1517- i++;
1518- if (strstr (curr, " shared" )) {
1519- wasm.memory .shared = strncmp (curr, " notshared" , 9 ) != 0 ;
1520- break ;
1521- }
1522- uint64_t max = atoll (curr);
1523- if (max > Memory::kMaxSize ) throw ParseException (" total memory must be <= 4GB" );
1524- wasm.memory .max = max;
1525- }
1515+ uint64_t max = atoll (s[i++]->c_str ());
1516+ if (max > Memory::kMaxSize ) throw ParseException (" total memory must be <= 4GB" );
1517+ wasm.memory .max = max;
15261518 return i;
15271519}
15281520
@@ -1557,6 +1549,10 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
15571549 if (wasm.getImportOrNull (im->name )) throw ParseException (" duplicate import" , s.line , s.col );
15581550 wasm.addImport (im.release ());
15591551 i++;
1552+ } else if (inner[0 ]->str () == " shared" ) {
1553+ wasm.memory .shared = true ;
1554+ parseMemoryLimits (inner, 1 );
1555+ i++;
15601556 } else {
15611557 if (!(inner.size () > 0 ? inner[0 ]->str () != IMPORT : true )) throw ParseException (" bad import ending" );
15621558 // (memory (data ..)) format
@@ -1565,7 +1561,7 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) {
15651561 return ;
15661562 }
15671563 }
1568- i = parseMemoryLimits (s, i);
1564+ if (!wasm. memory . shared ) i = parseMemoryLimits (s, i);
15691565
15701566 // Parse memory initializers.
15711567 while (i < s.size ()) {
@@ -1765,7 +1761,14 @@ void SExpressionWasmBuilder::parseImport(Element& s) {
17651761 }
17661762 // ends with the table element type
17671763 } else if (im->kind == ExternalKind::Memory) {
1768- j = parseMemoryLimits (inner, j);
1764+ if (inner[j]->isList ()) {
1765+ auto & limits = *inner[j];
1766+ if (!(limits[0 ]->isStr () && limits[0 ]->str () == " shared" )) throw ParseException (" bad memory limit declaration" );
1767+ wasm.memory .shared = true ;
1768+ parseMemoryLimits (limits, 1 );
1769+ } else {
1770+ parseMemoryLimits (inner, j);
1771+ }
17691772 }
17701773 if (wasm.getImportOrNull (im->name )) throw ParseException (" duplicate import" , s.line , s.col );
17711774 wasm.addImport (im.release ());
0 commit comments