Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static variables in header file may cause problems #60

Closed
myd7349 opened this issue Jan 31, 2023 · 0 comments
Closed

Static variables in header file may cause problems #60

myd7349 opened this issue Jan 31, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@myd7349
Copy link
Contributor

myd7349 commented Jan 31, 2023

Describe the bug

When exploring #58 with VS2022,I noticed that filepath is empty in windows.cpp.

Since filepath is declared in clipboard.hpp as a static variable, then each compilation unit that includes this header will have its own copy of this variable. Some of them may be initialized correctly, some may not.

In windows.cpp, these two places will reference filepath:

std::ifstream file(filepath.main / constants.pipe_file);

for (const auto& entry : fs::directory_iterator(filepath.main)) {

Though filepath is initialized in clipboard.cpp:

because clipboard.cpp and windows.cpp are two compilation units, filepath referenced by these two places in windows.cpp is still uninitialized. As a result:

fs::directory_iterator(filepath.main) // fs::directory_iterator("")

will raise an exception(File not Found).

To Reproduce

First, add copy $(TargetPath) to Command Arguments:

01

Then step into setWindowsClipboardDataFiles or setWindowsClipboardDataPipe, and dump the value of filepath.main and address of filepath.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
Hi! @Slackadays Instead of screenshots, I made a short video to demonstrate the issue. And the reason I did not take screenshots is once I started to debugging Clipboard with VS2022, the Print Scrn key won't work any more.

https://drive.google.com/file/d/1cChilbVmh1uqt4OUv-_a3JDdbsij2cxu/view?usp=sharing

Additional context
Add any other context about the problem here.

Before you post
Please make sure you check previous bug reports before filing a new one.
This will help keep the Issues section less cluttered. :)

@myd7349 myd7349 added the bug Something isn't working label Jan 31, 2023
Slackadays added a commit that referenced this issue Feb 1, 2023
Fix directory iteration exception caused by empty path (#60)
@myd7349 myd7349 closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant