diff --git a/src/c/parser/expr.rs b/src/c/parser/expr.rs index 56c4918..0ef79c6 100644 --- a/src/c/parser/expr.rs +++ b/src/c/parser/expr.rs @@ -240,6 +240,7 @@ impl<'a> Parser<'a> { if let CTokenKind::StringLiteral(encoding, string) = &self.input.peek().kind { let string = string.clone(); let encoding = encoding.clone(); + self.input.advance(); return Ok(ExprKind::StringLiteral(encoding, string).at(source)); } diff --git a/src/c/translation/expr/string.rs b/src/c/translation/expr/string.rs index 86b2834..aa61c03 100644 --- a/src/c/translation/expr/string.rs +++ b/src/c/translation/expr/string.rs @@ -3,6 +3,7 @@ use crate::{ c::{encoding::Encoding, parser::ParseError}, source_files::Source, }; +use std::ffi::CString; pub fn translate_expr_string( encoding: &Encoding, @@ -10,7 +11,9 @@ pub fn translate_expr_string( source: Source, ) -> Result { if let Encoding::Default = encoding { - return Ok(ast::ExprKind::String(content.into()).at(source)); + // TODO: Add proper error message? + let content = CString::new(content).expect("valid null-terminated string"); + return Ok(ast::ExprKind::NullTerminatedString(content).at(source)); } todo!("translate non-default encoding C string")