Skip to content

Commit f469b83

Browse files
authored
fix: reading memory of stack allocated object past its scope (leejet#91)
1 parent 8124588 commit f469b83

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

common/common.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ std::string basename(const std::string& path) {
370370
return path;
371371
}
372372

373-
const char* get_image_params(SDParams params, int seed) {
373+
std::string get_image_params(SDParams params, int seed) {
374374
std::string parameter_string = params.prompt + "\n";
375375
if (params.negative_prompt.size() != 0) {
376376
parameter_string += "Negative prompt: " + params.negative_prompt + "\n";
@@ -387,5 +387,5 @@ const char* get_image_params(SDParams params, int seed) {
387387
}
388388
parameter_string += ", ";
389389
parameter_string += "Version: stable-diffusion.cpp";
390-
return parameter_string.c_str();
391-
}
390+
return parameter_string;
391+
}

common/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ void print_usage(int argc, const char* argv[]);
4040

4141
void parse_args(int argc, const char** argv, SDParams& params);
4242

43-
const char* get_image_params(SDParams params, int seed);
43+
std::string get_image_params(SDParams params, int seed);

examples/cli/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int main(int argc, const char* argv[]) {
8787
std::string dummy_name = last != std::string::npos ? params.output_path.substr(0, last) : params.output_path;
8888
for (int i = 0; i < params.batch_count; i++) {
8989
std::string final_image_path = i > 0 ? dummy_name + "_" + std::to_string(i + 1) + ".png" : dummy_name + ".png";
90-
stbi_write_png(final_image_path.c_str(), params.width, params.height, 3, results[i], 0, get_image_params(params, params.seed + i));
90+
stbi_write_png(final_image_path.c_str(), params.width, params.height, 3, results[i], 0, get_image_params(params, params.seed + i).c_str());
9191
printf("save result image to '%s'\n", final_image_path.c_str());
9292
}
9393

0 commit comments

Comments
 (0)